C Technical Interview Questions – Operators

These C Technical Interview Questions post providing basic, intermediate and Hard level examples in C Operators. The practice of these examples makes you good in C programming.


What is the Output of following Code?
#include<stdio.h>
main()
{
int res = 10<20 ? 20<30 ? 10 : 20 : 30;
printf(“res : %d\n”,res);
}

  1. 20
  2. 10
  3. 30
  4. Invalid expression

Answer :

Ans : 2; Both the expressions 10<20 and 20<30 are true, hence the value is 10

What is the Output of following Code?
#include<stdio.h>
int main()
{
int a = 8;
printf(“%d , %d”, a << 1,a << 2);
return 0;
}

  1. 64,64
  2. 16,16
  3. 16,32
  4. 32,32

Answer :

Ans : 3; a<<1 will shift the value by 1 location prints, it doesn’t modify the original value of ‘a’

What is the Output of following Code?
#include<stdio.h>
int main(void)
{
int a, b=10 ;
a = 20 == b ;
printf(“a : %d \n”,a);
return 0;
}

  1. 10
  2. 20
  3. Error : L value required
  4. 0

Answer :

Ans : 4; the expression value of 20==b is 0, hence a value is 0

What is the Output of following Code?
#include<stdio.h>
main()
{
int x=5 , y=3;
x++ ? –y : ++x ;
printf(“%d,%d”,–x , –y);
}

  1. 4, 1
  2. 5, 1
  3. 6, 2
  4. 6, 1

Answer :

Ans : 2; In the condition x value substitues and increases, hence value is 6 and that will be decreased once again in the printf function before printing(–x)

What is the Output of following Code?
#include<stdio.h>
main()
{
int a =5;
a = a++ + ++a ;
printf(“a : %d\n”,a);
}

  1. 12
  2. 10
  3. 11
  4. 13

Answer :

Ans : 4; One time a value increase and substitutes everywhere in the expression like a=6+6,  . finally a=12 value increases once again using a++. hence the value is 13

What is the Output of following Code?
#include<stdio.h>
void main()
{
int x;
x = 4%5==4%2+3;
printf (“x = %d”,x);
}

  1. 4
  2. 5
  3. 0
  4. 1

Answer :

Ans : 3;  Mod operator higher priority than + operator, hence the expression is 4==5, so the result is 0

What is the Output of following Code?
#include<stdio.h>
main()
{
int x=5 , y;
y = x*2 + ++x ;
printf(“%d,%d”,x, y);
}

  1. 6, 18
  2. 6, 16
  3. 6, 17
  4. 5, 16

Answer :

Ans : 1; Initially x value increases and substitues in the expression as y=6*2+6, hence the value of y is 18

What is the Output of following Code?
#include<stdio.h>
main()
{
int a=5;
printf(“%d,%d,%d”,++a, a++ , –a);
}

  1. 4,4,6
  2. 6,4,4
  3. 6,6,5
  4. 4,5,6

Answer :

Ans : 2; Evaluate expressions from right side and print the values from left side.

What is the Output of following Code?
#include<stdio.h>
int main()
{
int x ;
x=10,20,30;
printf(“%d”,x);
return 0;
}

  1. Error
  2. 10
  3. 30
  4. 60

Answer :

Ans : 10; Stores left most value when we assign in such as way

What is the Output of following Code?
#include<stdio.h>
main()
{
int x=3,y=7,z;
z = ++x * y– ;
x = y– + ++z ;
y = z– + x++ ;
printf(“%d,%d,%d”,x,y,z);
}

  1. 34, 63 , 26
  2. 26, 64 , 28
  3. 36 , 64, 28
  4. 34, 64 , 26

Answer :

Ans : 3; Analyze the code by writing printf function after every single statement.

C Technical Interview Questions – Operators – 3

Share this