C - Functions - Discussion

You Are Here :: Home > C > Functions - Discussion

 



Q.

What will be the output of the following program.

main()
{
C()
{
c()
{
printf(" shalu\n");
}
printf("shalini\n");
}
printf("hi!");
}

A. shalu B. shalini
C. hi! D. Error message

Answer: Option D
Explaination:

Statement missing ; in function main The compiler reports an error saying there is a missing semicolon. But where is it missing? After C(). But suppose we only want to define the function C(), logically we shouldn't be required to give a semi-colon after C().That's the point. At the most you can call a function from within the body of another function. you are not allowed to define another function within the body of another function. And that is what the above program is attempting to do. It is trying to define C() and c() in main(), which ia not acceptable,hence the error message.



Discussion

Your Comments Goes here...
NameDiscussion