C Output Questions

  1. Find Error/Output in follwing code:
  2.                             
    int main() {
    
      char c = 'f';
      switch (c) {
        default: printf("unknown colour ");
        case 'r': case 'R': printf("Red ");
        case 'g': case 'G': printf("Green "); break;
        case 'b': case 'B': printf("Blue");
      }
    }
    1. Red Green Blue
    2. Error
    3. Green unknown colour Red
    4. unknown colour Red Green
Answer :
D
Explanation:
Added By : Abhishek

  1. Find Error/Output in follwing code:
  2.                             
    int main() {
    
      int a = 100, b = 74;
      if (a++ > 100 && b++ > 200)
        printf("High values with a = %d b = %dn", a, b);
      if (a++ < 100 || b++ < 200)
        printf("Low values with a = %d b = %dn", a, b);
     }
    1. Low values with a = 100 b = 74
    2. Low values with a = 101 b = 73
    3. Low values with a = 102 b = 75
    4. Low values with a = 104 b = 75
Answer :
C
Explanation:
Added By : Jayesh


  1. Find Error/Output in follwing code:
  2.                             
    int main() {
    
      char p[] = "%dn";
      p[1] = 'c';
      printf(p, 65);
      int k=40, *a;
      a = &k;
      (*a)++; k++;
      printf("n k=%d",k); 
    }
    1. c k=40
    2. b k=44
    3. A k=42
    4. a k=40
Answer :
C
Explanation:
Added By : Tarun

  1. Find Error/Output in follwing code:
  2.                             
    int main() {
    
      int x = 1;
      while(x = 0)
        printf("hello"); 
    }
    1. hello
    2. No output
    3. Infinite time hello display
    4. Error in code
Answer :
B
Explanation:
Added By : Nikita

  1. Find Error/Output in follwing code:
  2.                             
    int main() {
    
      int x = 0, y = 0;
      if(x > 0)
        if(y > 0)
          printf("True"); 
      else
        printf("False"); 
    }
    1. No Output
    2. True
    3. False
    4. Error because of dangling else problem
Answer :
A
Explanation:
Added By : Sachin

  1. Find Error/Output in follwing code:
  2.                             
    main() {
    
     int i = 2, *j;
     j = &i;
     printf("%d", i**j*i+*j); 
    1. Syntax error due to Invalid expression in printf
    2. Print junk value
    3. 16
    4. 10
Answer :
D
Explanation:
Added By : Seema Jain


  1. Find Error/Output in follwing code:
  2.                             
    int main() {
    
     int x,y,z;
     x = '1'-'0'; /* line-1 */
     y = 'a'-'b'; /* line-2 */
     z = x + y;
     printf("%d",z); 
    1. 0
    2. Error because of incorrect line-1 only.
    3. Error because of incorrect line-1 and line-2.
    4. Error because of incorrect line-2 only.
Answer :
A
Explanation:
Added By : Kritika Garg

  1. Find Error/Output in follwing code:
  2.                             
    void fn() {
    
     int a = 10;
     static int b = 20;
     printf("a = %d b = %d", ++a, ++b);

    int main() {
     fn();
     fn();
     return 0;
    }
    1. <p>a = 11 b = 21 a = 11 b = 22<br></p>
    2. <p>a = 11 b = 21 a = 11 b = 22<br></p>
    3. <p>a = 11 b = 21 a = 11 b = 22<br></p>
    4. <p>a = 11 b = 21 a = 11 b = 22<br></p>
Answer :
B
Explanation:
Added By : Prachi Gupta

Social Sharing
Search