I saw other questions about having two main()'s in C program:
I'm using CodeBlocks
But please consider this program:
void main()
{
void main()
{
printf("hello!");
}
printf("World!");
}
prints only "World!".
Standard C and C++ do not support nested functions, but:
and CodeBlocks use GCC compiler only, hence you're are not getting any error.
For the question
about having two
main()
in C program
No you can't, this is how compiler interprets where to start executing the program. It will take one of the main as local.
Also,
you are not getting "hello" printed
because when compiler starts executing your first main()
function, it takes the second main()
as local, and because you haven't called the second main()
, the string doesn't get printed.