0
#include <stdio.h>
int main()
{
    static int i = 5;
    if (--i){
        printf("%d ", i);
        main(10);
    }
}    

I was reading article on geeksforgeek the difference between int main(void) and int main() but I am confused. How main function taking arguement?

Nike S
  • 7
  • 1

1 Answers1

1

int main(void) { }

Here, you are telling your compiler explicitly that your main() function is not going to take any arguments. This prototype of main() function is standard.

int my_func(void)
{
    return 100;
}

// the above function can be called as:
// 1. my_func(); --> good
// 2. my_func(21); --> error
// 3. my_func("STACKOVERFLOW"); --> error

int main() { }

Here, you are telling your compiler implicitly that your main() function is not going to take any arguments. But, there's a plot twist, in C leaving the function without any arguments (type function() { }) means you can put any value/variable in it while calling that function. This prototype should be avoided.

int my_func()
{
    return 100;
}

// the above function can be called as:
// 1. my_func(); --> no error
// 2. my_func(21); --> no error
// 3. my_func("STACKOVERFLOW"); --> no error
Darth-CodeX
  • 2,166
  • 1
  • 6
  • 23