Difference Between Int Main And Void Main In C Programming

Prashant | Wed, 10 Jun, 2020 | 164

Difference between int main and void main

The standard statements are :-

int main()
void main()
Difference betwèen int main and void main: See like any other function, main is also a function but with a special characteristic that the program execution always start from main. So the function main needs arguments and a return type. These int and void are its return type. Void means it will not return any value, which is also ok.
But if want to know whether the program has terminated successfully or not, we need a return value which can be zero or a non zero value. Hence the functuon becomes int main () and is recommended over void main ().

Example ;-

void main()
int add(int a,int b)
int c;
printf("Output: %d",c);
return 0;

now see the guys when you use the function having some parameters than time return some a and b values so now use int main function
if use void add(int a,int b) system throw the error. so i use int add(int a,int b)

Note :-

1. int main() is preferred over void main(), as per standards, and most new compilers supports int main() rather than void main().
2. int main() can help to return the error code if your program fails due to some error.
(Pre exception handling days, now you may use exception handling to handle issues,
perhaps that's the reason in java we go as public static void main () )







Related Articles :- 

1Introduction And Getting Started With C

2Basic Of C Language

3. Why We Should Use C Language

4. Applications Of C Programming

5. Basic Rules For Writting C Program

6. Keywords In C Language

7. Comments In C Programming

8. Tokens In C

9. Difference Between Int Main And Void Main

10. C Processor And Macros

11. Variables In C

12. Types Of Variables In C

13. Difference Between Local And Global Variable

14. Difference Bwtween Auto / Extern / Static Variable

15. Constant In C

16. How To Access Global Variable Using Extern Keyword In C

17. Exit And Return Staterment In C

18. Print Float Value Upto N Decimals In C Programming

19. How To Print Multiline Message Using Single Printf In C Programming ?

20. What Value Returned By Scanf Function In C Language ?

21. What Value Is Returned By Printf And Scanf In C

22. What Do 'Lvalue' And 'Rvalue' Mean In C/C++?

23. Errors In C Programming ?

Leave a comment