3 main() in .c file
3.1 Examples
- In .c file, such as “main.c”, we can code main() as follows
- Example 1
```r #include<stdio.h> int main(){ int a,b; a = 3; b = 4; printf(“a+b=%d”,a+b);
fflush(stdin); getchar(); return 0; } ``` - Example 2
```r #include<stdio.h> int main(int argc, char* argv[]){ int a,b; a = 3; b = 4; printf(“a+b=%d”,a+b);
fflush(stdin); getchar(); return 0; } ``` - Example 3
```r #include<stdio.h> main(int argc, char* argv[]){ int a,b; a = 3; b = 4; printf(“a+b=%d”,a+b);
fflush(stdin); getchar(); } ``` - Example 4
```r #include<stdio.h> main(){ int a,b; a = 3; b = 4; printf(“a+b=%d”,a+b);
fflush(stdin); getchar(); } ```
3.2 In the final examination, please use Exmple 1 only
- Some lines can be deleted
- “#include<stdio.h>” can be deleted if you have no input and output
- “fflush(stdin);” can be deleted if you have no input, such as “scanf(”Input a = %d“,&a);
- “getchar();” can be deleted if you do not want to see results on screen, or if you use “Start Without Debugging” under the button “Debug”
- In the final examination, both “fflush(stdin);” and “getchar();” can be ignored
- Like this
```r #include<stdio.h> int main(){ int a,b; a = 3; b = 4; printf(“a+b=%d”,a+b);
return 0; } ```