Machine-translated by Google. Questions are authored in English.
Top

Discussion

What will be the output of the following C code?

int main () 
{ 
   printf("starting of program\n"); 
   printf("program exits\n"); 
   exit(0);  
   printf("program ends\n");  
   return(0); 
}

 

  • A.
    starting of program
    program exits
    program ends
  • B.
    starting of program
    program exits
  • C.
    starting of program
    program ends
  • D.error

Answer: B

Correct answer: starting of program program exits

exit(0) terminates the program immediately, so the third printf and the return are never reached. Only the first two lines appear. Unlike return from main, exit can be called from anywhere and ends the whole program.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.