I am a c beginner, I would like to know what is the difference between int main(void) vs int main().
I have the feeling it is the same but just to make sure!!!!
This is a discussion on int main(void) VS int main() within the C Programming forums, part of the General Programming Boards category; I am a c beginner, I would like to know what is the difference between int main(void) vs int main(). ...
I am a c beginner, I would like to know what is the difference between int main(void) vs int main().
I have the feeling it is the same but just to make sure!!!!
i think it is the same. i would use int main() myself, since it saves 4 letters typing.
Whenever I write any function that takes on parameters I always specify 'void'. I just think it makes it obvious to the reader that the function takes no parameters. Just habit I guess.
"...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers
Hi,
Though I am not very sure of this, I think the use of "void" allows certain old C compilers to handle functions that do not take any arguments. For the new ones this is redundant.
Here's an extract from the draft C99 standard:
However, within the document some example code also uses5.1.2.2.1 Program startup
1 The function called at program startup is named main. The implementation declares no prototype for this function. It shall be defined with a return type of int and with no parameters:
int main(void) { /* ... */ }
or with two parameters (referred to here as argc and argv, though any names may be used, as they are local to the function in which they are declared):
int main(int argc, char *argv[]) { /* ... */ }
or equivalent; or in some other implementation-defined manner.
>int main()
Personally, I use
>int main(void)
if there are no arguments required.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
babu,
in C, if u dont specify any argueemts , it means tht the function will behave normally for any type and number of arguemnts....
so if u dont want a function to accept atguemtns thn u declare its parameters as "void".
in c++ , no args means function does not take any arguemsnts.
so
void print()
{
puts("c is easy.");
}
int main()
{
print();
print(1); /* works if print is declared as void print(void) this fails to compile. */
return 0;
}