To check the execution sequence of the code, I have added printf statement just below the main():

int main(int argc, string argv[])
     // greet player
     printf("abc \n");

However, It doesn't print abc and prints GAME OF FIFTEEN directly. When I checked with gdb it do goes to printf line. I can't understand why printf("abc \n"); is not executed ?

1 Answer 1


Have you noticed that when the fifteen program starts up, the entire screen is cleared? Compare that to the other programs before this, which just display the output directly after the command line.

The reason for this happening is shown in the greet() function:

void greet(void)
    printf("GAME OF FIFTEEN\n");

Here we see that the first line called is the clear() function. From the observed behaviour we might assume that this is clearing the screen. This is all happening after your own printf message.

So what is actually happening is:

  1. Your program begins running.
  2. Prints out "abc\n".
  3. Calls greet().
  4. greet() calls clear().
  5. clear clears the screen, including the message you just printed.

The reason you see your message in gdb is that you are able to execute one command at a time, which gives you time to see the output. In normal operation it does exactly the sam thing, it just happens too quickly for you to see.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .