- 4

What is the difference between main()function in C and C++

6th Apr 2017, 5:58 AM
Karika Batra
Karika Batra - avatar
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
6th Apr 2017, 6:07 AM
Hatsy Rei
Hatsy Rei - avatar
+ 15
// hello guys test this code in turbo C #include<iostream.h> #include<conio.h> void main(){ clrscr(); cout<<" Hello World"; getch(); }
22nd Apr 2017, 4:21 PM
Joobin Jacob ◆ ܝܘܼܒܝܼܢ ܝܹܩܲܒ ◆‎
+ 11
we can use void main() in turbo C++ compiler .
22nd Apr 2017, 4:12 PM
Joobin Jacob ◆ ܝܘܼܒܝܼܢ ܝܹܩܲܒ ◆‎
+ 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.
6th Apr 2017, 6:21 AM
Wen Qin
Wen Qin - avatar
+ 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...
6th Apr 2017, 11:54 AM
Sanjay Gandhi
Sanjay Gandhi - avatar
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.
13th Sep 2018, 1:07 PM
dhiraj kumar #
dhiraj kumar # - avatar
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!
13th Feb 2020, 4:59 AM
Greeeny
Greeeny - avatar