What’s the difference between:
main()
int main()
void main()
is there another way of initializing main?
Thx
What’s the difference between:
main()
int main()
void main()
is there another way of initializing main?
Thx
What’s the difference between:
main()
int main()
void main()
I dont know about main(), but int main() returns an integral, void main() does not return anything.
is there another way of initializing main?
I supose you can do bool main(), double main(), float main() and so on.....
Why drink and drive when you can smoke and fly?
the one other way of initializing main() is
which makes use of the outside operating system, for things like command line arguments.Code:int main(int argc,char *argv[])
main() = void main()
Void main is bad. goto search in the upper right corner. Type in void main and you'll see why.
In short. Void main doesn't return a value, and sometimes it returns a random value to the operating system, in all cases this is BAD.
int main() = GOOD! Look for a user named Salem, look at his quotes.
int main() returns a number (0 on success) and the OS will be able to tell if the program ran smoothely based on the numbers returned.
as for returning different types... depends on the OS, but usually NO. char main() I guess would work cuz its actually a short unsigned int.
WinMain() returns something besides an int, I think
For all intended purposes, stick to int main()
-LC
Asking the right question is sometimes more important than knowing the answer.
Please read the FAQ
C Reference Card (A MUST!)
Pointers and Memory
The Essentials
CString lib
>>char main() I guess would work cuz its actually a short unsigned int.
void main( ) might also work. But it's not actually legal C/C++. The only ways that you can define main are:
Code:int main( void ) AND int main( int argc, char **argv )
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
Thx. i've came across smething else
int main(void)
What's this?
Thx Salem. got another thing i don't quite understand
what does argc and *argv[] means n what do they do.int main(int argc,char *argv[])
argc is the number of arguments supplied to the program, *argv[] is the pointer to the argument strings.Originally posted by nightingale
Thx Salem. got another thing i don't quite understand
what does argc and *argv[] means n what do they do.
$ENV: FreeBSD, gcc, emacs
I've hurd that void main () is legal but it should only be used when you don't want your program to return a value, and the only reason you shouldn't want this is when you make programs witch should run in the back of the OS but I could be wrong.....
They say that if you play a Windows Install CD backwords, you hear satanic messages. That's nothing; play it forward and it installs Windows.
>>I've hurd that void main () is legal
void main( ) is never legal. Period.
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
>>I've hurd that void main () is legal
>void main( ) is never legal. Period.
Not true for C in general -- but correct for hosted environments (if you're using a freestanding environment, you probably know it; if you've never heard of the distinction, you're probably using a hosted environment*).
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
Lets say the program is called "hello"Code:int main(int argc, char* argv[])
and you run it on a command line like:
hello
argc = 1, argv[0] = "hello"
if you run it like
hello these are my arguments to the program
argc = 8
argv[0] = hello
argv[1] = these
argv[2] = are
argv[3] = my
argv[4] = arguments
argv[5] = to
argv[6] = the
argv[7] = program
When the Kernel runs the program, it passes the parameters and parameter info through these two parameters.
argc = Number of Arguments
argv[] = Array containing the arguments
as for void main()
just don't use it!
You will be flamed badly on these boards if you do.
read Salem's quote!
-LC
Last edited by Lynux-Penguin; 07-24-2003 at 02:37 PM.
Asking the right question is sometimes more important than knowing the answer.
Please read the FAQ
C Reference Card (A MUST!)
Pointers and Memory
The Essentials
CString lib
Another FAQ link that answers your questions:
http://faq.cprogramming.com/cgi-bin/...&id=1043284392
I suggest you browse the whole FAQ so that you try to find answers to your questions before posting them here.
What is this anyway, void main week?
[edit]Even this is in the FAQ:
>>void main( ) is never legal. Period.<<
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Argument passing is done by the shell.Originally posted by Lynux-Penguin
When the Kernel runs the program, it passes the parameters and parameter info through these two parameters.
$ENV: FreeBSD, gcc, emacs
THe shell doesn't run the program, the kernel does
The shell tells the kernel to run it.
Read
Linux Core Kernel, 2nd Edition
And read about ELF, the same applies to almost every OS.
Correct me if I'm wrong. I just read a lot of forums, some of my information is opinion based, but I almost sure of this.
-LC
Last edited by Lynux-Penguin; 07-24-2003 at 06:54 PM.
Asking the right question is sometimes more important than knowing the answer.
Please read the FAQ
C Reference Card (A MUST!)
Pointers and Memory
The Essentials
CString lib