What You Must Know The Difference Between: void main() And int main()

0
void main vs int main in c

In C and C++ works the same definition that void main() and int main(). Here the void can be technically called as don’t return anything.

It takes statements and returns a value. The first thing we should keep in mind is that main() is the function that starts the program. This function calls the operating system. The main() returns a value to the operating system.

With void main(), the function won’t return any value, while int main() indicates that data of the integer type can be returned by the main() function.

If we have a simple program that isn’t set up to terminate before it reaches the last line of code, or when the code is error-free, we can use the void main() function. We have to return some integer values (zero or non-zero) when we use the exit() method, which terminates the program.

Simple Syntax of void main()

#include<stdio.h>void main() // won't return any value{printf(" Hello World!"); // printing the "Hello World!"}// Output:Hello World!

Simplex Syntax of int main()

#include<stdio.h>int main(){printf(" Hello World!");return 0;  //return statement returning value 0 as return type is int}

Conclusion:

So You can better use the int main() or int main(void). If you have any queries about the C/C++, comment below.

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.
Post a Comment (0)
To Top