What's the diff between main(void) and main() ....they seem the same to me!!
Also what does Return 0 mean??
Remember i am a newbie to this stuff!!!
What's the diff between main(void) and main() ....they seem the same to me!!
Also what does Return 0 mean??
Remember i am a newbie to this stuff!!!
>What's the diff between main(void) and main() ....they seem the same to me!!<
I don't see a difference. With main(void) you're just explicitly saying something that in main() you are assuming...
>Also what does Return 0 mean??<
Functions in C either return a value (to the caller) or they don't.
In main(), 0 is normally used to indicate to the operating system that the program executed and terminated properly. A non-zero value would imply something went wrong.
God, I suck at explaining things...
Last edited by Hillbillie; 03-30-2002 at 02:52 PM.
Hi ,
int main(void) - meaning no parameters are passed to main function
Return 0 is a value that is returned to main ie. int main expects a n integer to be returned to it.
And To All Those Opposed, WELL !!!
>Deleted< " Looks like a serial no."
void main(void)
{
}
>void main(void)
>{
>}
Function main should return an int.
Code:int main () { int retval; /* some other code */ return retval; }
thanx to all!!
you all rock!
There's a slight difference, in c but not c++, you can do
Code:void f() { /* code */ } int main(void) { f(100, 100); return 0; }
As nick rightly pointed out there is a difference in C between main(void) and main().
main(void) explicitly tells that the function accepts no parameteres.
main() or for that matter any function(), at the time of being called can accept any number of parameters. But you can't use them inside the function since neither the declaration nor the definition have provided for any stack for the variables.
so in the following code
int cfunc();
void main ()
{
int x = 4;
int y = 8;
cfunc(x, y);
}
int cfunc()
{
return (printf ("I don't know how to access the stack of this function call \n");
}
if you want to know how is it possible, you should read some of the source files included, and look for the implementation of main.
> void main ()
Pay no attention to the man behind the curtain. He has no idea what he's doing.
Quzah.
Hope is the first step on the road to disappointment.
No, your suppose to use the parameters this way.
Code:int f(); int main() { int n = f(5); printf("f(%d) = %d\n", 5, n); return 0; } int f() { int dummy; int* p = &dummy + 3; return *p + 1; }
Um. No. You are SUPPOSED to use parameters THIS WAY:No, your suppose to use the parameters this way.
code:--------------------------------------------------------------------------------
int f();
int main()
{
int n = f(5);
int f( int myparam1, char *myparam2, etc etc )
There is a reason you can specify the arguments to a function: It's easily readable and understandable by people using your code. No one wants to look at that horrible excuse for "programming". That is bad practice and I for one would in no way want to have to fix your screwed up code when you fail to do the simplest things correctly...
Quzah.
Hope is the first step on the road to disappointment.