Some questions on compound statements

  1. What would be the difference in the output of the following two programs?
    #include<stdio.h>
    #include<stdlib.h>
    
    int main()
    {
          int i = 3;
          if (i==4) {
                i++;
                printf("%d\n",i);
          }
          
          return EXIT_SUCCESS;
    }
    
    Plain source version to compile.

    #include<stdio.h>
    #include<stdlib.h>
    
    int main()
    {
          int i = 3;
          if (i==4) 
                i++;
                printf("%d\n",i);
          
          
          return EXIT_SUCCESS;
    }
    
    Plain source version to compile.

  2. Try compiling and running the programs to see if you were right.

Answers to these questions.


Back to the notes on compound statements.