c - What does this program do? (Self calling main function + getchar) -


can me explain question past exam paper? when compile it, never satisfied input. also, reason self calling main function?

what following program do? justify answer.

#include <stdio.h> int main ( void ) {     int c;     if (( c = getchar() ) != eof) {         main();         printf("%c", c);     }     return 0;  } 

the program is satisfied, eof returned getchar(), achieved entering ctrl^z (windows console) or ctrl-d (linux). program continue recurse until happens (unless stack breaks). after getting eof drops out of recursion printing inputs in reverse order (including character representing eof).

note eof typed must first keystroke after enter key.


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -