Can someone tell me what the advantage is of using Int Main instead of Void Main? And, does Void Main also return a value in the end? - -
This may sound kinda noob but I am
Can someone tell me what the advantage is of using Int Main instead of Void Main? And, does Void Main also return a value in the end? - -
This may sound kinda noob but I am
void main( ) is not valid C or C++. The only valid return type for main is int.
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
int main is standard (look for Salem's avatar), void main is not (and therefore, incorrect). The return value tells the system (and possibly other programs) the exit status of your program.
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
struct StringData
{
char string[100];
};
void main()
{
StringData data[10];
for (int x=0;x<9;x++)
{
cout<<"Please enter a variable #"<<x<<":";
cin>>data[x].string;
}
cout<<"Data "<<data[1].string<<endl;
cout<<"Data "<<data[2].string<<endl;
cout<<"Data "<<data[3].string<<endl;
system("pause");
}
________________
These are both the same, only once thing is different!
The upper code uses VOID MAIN and the bottom code
use INT MAIN. They both work, no difference at all! Does
it matter what I use??
________________
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
struct StringData
{
char string[100];
};
int main()
{
StringData data[10];
for (int x=0;x<9;x++)
{
cout<<"Please enter a variable #"<<x<<":";
cin>>data[x].string;
}
cout<<"Data "<<data[1].string<<endl;
cout<<"Data "<<data[2].string<<endl;
cout<<"Data "<<data[3].string<<endl;
system("pause");
}
You should always use int main( ), because void main( ) is not valid C++.
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
OKay, thx for the advice!
I noticed that some programs contain a \n in cout functions.
like this:
cout<<"\nHello";
Why is this? I couldn't find the answer in a tutorial, but I know it is used in other functions.
'\n' is the new-line character. When used with cout, it is roughly equivalent to endl.
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.
That depends on what you mean by "work". On your particular compiler, it may give the results you expect. But just because *YOUR* compiler allows incorrect code to compile doesn't mean that other compilers will.Originally posted by FromHolland
These are both the same, only once thing is different!
The upper code uses VOID MAIN and the bottom code
use INT MAIN. They both work, no difference at all! Does
it matter what I use??
void main IS an error. It's not legal C++. It's unfortunate, but many compilers don't report it as an error -- this is a flaw in the compilers, though. It "works" on many compilers as an undesired byproduct of how those compilers implement name mangling. It's not guaranteed to work.
Heck, I've seen compilers that would compile:
but it does NOT mean it will perform as expected, and it does NOT mean the program is legal C++Code:class Node{ /*...*/ }; Node main(Node in){ }
Last edited by Cat; 06-12-2003 at 03:11 PM.
Is this question going to stop someday?!
Almost every month we have a new post about "int main() or void main()", "int main() VS. void main()"....
I think mods should reply to this kind of post with "READ THE FAQ'S", and then close the post!
What do you think...
none...