Hello Everyone,
Greeting for the day!
I have seen this code at some portal and thought to give it a try.
Code:void tom(void)
{
static int jerry;
printf("%d\n", ++jerry);
}
int main()
{
void tom(), tom(); // issue
tom(), tom();
return 0;
}
The problem catches my attention because of "void" before the function call (highlighting it as //issue). I thought that since function return as void, adding "void" precede function call "tom" would act as casting. At my quick glance, I expected it to print 1 2 3 4 because of the behavior of the static keyword but it seems that my guess was incorrect and it prints just 1 2.
I further debug this code to get narrow down into details but it seems that line "void tom(), tom();" didn't executed at all and my PC jumps next line skipping these two function.
I made sure twice that no warning has generated because of "void".
I replace both "void" as "int" expecting some new warning/error/ result but nothing had happened. Till here I thought that may be compiler is not considering it as function call because of "void" so I changes only the return type of function as int, keeping "void" inside the main to which surprisingly compiler produces error "conflicting type for "tom".
Can anyone please explain why this behavior?