Q. When 1 is entered, the output of the code below is?

Code:
#include <stdio.h>

void main() 
{        int ch;        
printf(“enter a value btw 1 to 2:”); 
       scanf(“%d”, &ch);    
    switch (ch, ch + 1)   
     {          
     case 1:             
         printf(“1\n”);         
             break;          
     case 2:              
        printf(“2”);           
           break;     
   }
 }
  • (A) 1
  • (B) 2
  • (C) 3
  • (D) Run time error
πŸ’¬ Discuss
βœ… Correct Answer: (B) 2

Q. Output is:

Code:
#include <stdio.h>

void main() {     
   int x = 1, y = 0, z = 5;     
   int a = x && y && z++;     
   printf(“%d”, a);
 }
  • (A) 1
  • (B) 0
  • (C) 5
  • (D) 6
πŸ’¬ Discuss
βœ… Correct Answer: (B) 0

Q. Output is

Code:
#include <stdio.h>

void main() {    
    int x = 20;     
   printf(“%x”, x);
 }
  • (A) 14
  • (B) 16
  • (C) 20
  • (D) 24
πŸ’¬ Discuss
βœ… Correct Answer: (A) 14

Q. Output is

Code:
#include <stdio.h>

void main() {    
    int x = 4;     
   int y = 5;     
   x = ++x + y–;     
   printf(“%d  “, x);    
    printf(“%d”, y);
 }
  • (A) 9 5
  • (B) 10 5
  • (C) 9 4
  • (D) 10 4
πŸ’¬ Discuss
βœ… Correct Answer: (D) 10 4

Q. Output is

Code:
#include <stdio.h>
 int main() {       
 int a = 10;        
double b = 5.6;        
int c;
   c = a + b;        
printf(“%d”, c); 
}
  • (A) 15.6
  • (B) 15
  • (C) 16
  • (D) 15.5
πŸ’¬ Discuss
βœ… Correct Answer: (B) 15

Q. What is the difference between the following 2 C codes?

Code:
#include <stdio.h> //Program 1
    int main()
    {
        int d, a = 1, b = 2;
        d =  a++ + ++b;
        printf("%d %d %d", d, a, b);
    }

#include <stdio.h> //Program 2
    int main()
    {
        int d, a = 1, b = 2;
        d =  a++ +++b;
        printf("%d %d %d", d, a, b);
    }
  • (A) No difference as space doesn’t make any difference, values of a, b, d are same in both the case
  • (B) Space does make a difference, values of a, b, d are different
  • (C) Program 1 has syntax error, program 2 is not
  • (D) Program 2 has syntax error, program 1 is not
πŸ’¬ Discuss
βœ… Correct Answer: (D) Program 2 has syntax error, program 1 is not

Q. What will be the output of the following C code considering the size of a short int is 2, char is 1 and int is 4 bytes?

Code:
#include <stdio.h>
    int main()
    {
        short int i = 20;
        char c = 97;
        printf("%d, %d, %d\n", sizeof(i), sizeof(c), sizeof(c + i));
        return 0;
    }
  • (A) 2, 1, 2
  • (B) 2, 1, 1
  • (C) 2, 1, 4
  • (D) 2, 2, 8
πŸ’¬ Discuss
βœ… Correct Answer: (C) 2, 1, 4

Q. What will be the final values of i and j in the following C code?

Code:
#include <stdio.h>
    int x = 0;
    int main()
    {
        int i = (f() + g()) | g(); //bitwise or
        int j = g() | (f() + g()); //bitwise or
    }
    int f()
    {
        if (x == 0)
            return x + 1;
        else
            return x - 1;
    }
    int g()
    {
        return x++;
    }
  • (A) i value is 1 and j value is 1
  • (B) i value is 0 and j value is 0
  • (C) i value is 1 and j value is undefined
  • (D) i and j value are undefined
πŸ’¬ Discuss
βœ… Correct Answer: (C) i value is 1 and j value is undefined

Q. What will be the output of the following C function?

Code:
#include <stdio.h>
    void reverse(int i);
    int main()
    {
        reverse(1);
    }
    void reverse(int i)
    {
        if (i > 5)
            return ;
        printf("%d ", i);
        return reverse((i++, i));
    }
  • (A) 1 2 3 4 5
  • (B) Segmentation fault
  • (C) Compilation error
  • (D) Undefined behaviour
πŸ’¬ Discuss
βœ… Correct Answer: (A) 1 2 3 4 5

Q. What will be the value of the following assignment expression?

Code:
 (x = foo())!= 1 considering foo() returns 2
  • (A) 2
  • (B) True
  • (C) 1
  • (D) 0
πŸ’¬ Discuss
βœ… Correct Answer: (A) 2