Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"int main (vooid)"? How does that work?

Tags:

c

syntax

main

People also ask

How does int main () and void main () work?

The void main() indicates that the main() function will not return any value, but the int main() indicates that the main() can return integer type data. When our program is simple, and it is not going to terminate before reaching the last line of the code, or the code is error free, then we can use the void main().

Is int main void correct?

In C++, both fun() and fun(void) are same. So the difference is, in C, int main() can be called with any number of arguments, but int main(void) can only be called without any argument. Although it doesn't make any difference most of the times, using “int main(void)” is a recommended practice in C.


It's simply using the "old-style" function-declaration syntax; you're implicitly declaring an int parameter called vooid.


It's valid code, because myprog.c contains:

int main (vooid) // vooid is of type int, allowed, and an alias for argc
{     
  return 42; // The answer to the Ultimate Question
} 

vooid contains one plus the number of arguments passed (i.e., argc). So, in effect all you've done is to rename argc to vooid.


In C, the default type for a function argument is int. So, your program is treating the word vooid as int main(int vooid), which is perfectly valid code.


It is only gcc -std=c89 -Wall -o qq qq.c and gcc -std=gnu89 -Wall -o qq qq.c don't emit a warning. All the other standards emit a warning about implicit type int for vooid.

int main(chart) behaves the same way as does int main (vooid).

return vooid; returns the number of command line arguments.

I tested with gcc 4.4.5 on Debian testing system.