Really small doubt

I am confused b/n two kinds of main() functions, int main() and int main(void) and I am somewhat good at c++. Both runs the same code without error.
My question : What is the use of the (void). Index said, it does not accept parameter or something...Could somebody give their own explanation as to what it does??
() and (void) are exaxtly the same. The meaning of void is "nothing". So int main() and int main(void) is equivalent.
closed account (z05DSL3A)
In C++ there is no difference between int main() and int main(void), they both mean that main has no parameters.

In C there is a small difference; int main(void) means main takes no parameters but int main()means that it can take any parameters.

-----------=======-----------
Edit:

In the following code C++ will give errors on line 15 and 16 where as C will only error on on line 16.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <stdio.h>

int foo()
{
    return 1;
}

int fooToo(void)
{
    return 1;
}

int main()
{
  int bar = foo(3);
  int barToo = fooToo(3);

  return 0;
}
Last edited on
Why not line 15? I know C++ and in C++ if foo(3) is given, where c is passed as an argument, it will show error cause there is no pre-defined thing that there should a argument to the function.....
So in C, even though you do not declare a argument in the time of function declaration you still can pass it during call??
What would happen then?
Thank you.
Topic archived. No new replies allowed.