- 4
What is the difference between main()function in C and C++
7 Answers
+ 11
The valid signatures for both languages are:
int main(void);
int main(int argc, char* argv[]);
In the case of C++, there's no need to state void within the function header/prototype.
While some compilers may except void return type for main(), it has never been part of the language standard. Neither in C nor C++.
Check out this thread, which links to a bunch of other resources on the topic.
https://stackoverflow.com/questions/204476/what-should-main-return-in-c-and-c
+ 15
// hello guys test this code in turbo C
#include<iostream.h>
#include<conio.h>
void main(){
clrscr();
cout<<" Hello World";
getch();
}
+ 11
we can use void main() in turbo C++ compiler .
+ 6
A good thing to know : In C++, by default, you can ONLY return an int value. But in some cases with modifications, you can return other values, but never a void.
+ 5
in c ...if simply nothing is written it assumes by default void (void main())....and we can also use int main() and then return some interger....however in c++ we can not have void main...also if simply writes main ...it assumes by default int...
0
Main function of C may be void, when returns nothing. In C++ main can not be void. It will return int value. In c main function, we do declare all variables together in beginning of the program.
0
C++ programs also start with the main () function. The execution of every program starts with the main () function. The programming rules for c++ are same as c.
Exceptionally, while working with class and objects in c++ we write the main () function at the end of the program to create an object which is in no way possible in c language!