So I'm learning about functions in a book.
- It says we need to prototype or declare functions so the compiler can understand if they are correctly called or not.
But why does the main function works without a prototype?
I used to write main functions in my learning process like this:
int main(void)So it will not get any argument because of
(void)I tried to run my program with argument for example
> ./a.out 2int main(int y){ printf("%s %d\n","y is",y); }When I run it normally
yis 1, when run it with> ./a.out 1yis 2, when there is more than one argument it increases by one. So it's not the right way but what causes this?Declaring
yascharsays nothing so my guess is it works like the return value ofscanf(). It returns number of successful inputs.
gcc -Wall -Wextra -g