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 a=6,b=3;
b = a– + a– + a++;
b = b– ;
a = a++ + ++b;
printf(“%d,%d”,a,b);
}

  1. 22, 16
  2. 24, 18
  3. 23,17
  4. 20, 18

Answer :

Ans : 2; First expression –> b=6+6+6 , second expression–> b=18, third expression –> a=5+18

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

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

Answer :

Ans : 3; Expressions evalue from right side in the printf function and resultant values will be displayed from left side

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. 13
  3. 11
  4. 14

Answer :

Ans : 4; Value of ‘a’ increased by 2 pre-increments operators and substitute the final value everywhere in the expression as a = 7+7

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

  1. garbage value
  2. either 0 or 1
  3. 0
  4. 1

Answer :

Ans : 2; The value of a is garbage value. If the garbage value is positive or negative integer then the result is 1 and if the garbage value is 0, the result is 0

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

  1. 1, 3
  2. 3, 3
  3. 0, 3
  4. Compile time error

Answer :

Ans : 1; Arithmetic operators having higher priority than relational operators

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

  1. 4
  2. 5
  3. 6
  4. 7

Answer :

Ans : 2; i=1 value will be substituted in the expression as i=2+2*1 and finally i value is increased by 1 using i++ operator

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

  1. 10
  2. 30
  3. 40
  4. 70

Answer :

Ans : 2;  The right most value in parenthesis will be assigned to x.

What is the Output of following Code?
#include<stdio.h>
main()
{
short int a=8,b,c;
b = a << 3 ;
c = a >> 2 ;
printf(“[%d][%d]”,b,c);
}

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

Answer :

Ans : 4;

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

  1. 10
  2. 12
  3. Invalid expression
  4. 11

Answer :

Ans : 4; compiler add necessary spaces in the expression according to priority of operators, hence the expression become a=a++ + a ;

What is the Output of following Code?
#include<stdio.h>
int main()
{
printf(“%d %d %d”,sizeof(3.14),sizeof(3.14f),sizeof(3.14L));
return 0;
}

  1. 4,4,4
  2. 8,4,4
  3. 8,4,10
  4. 4,4,8

Answer :

Ans : 3; sizes of double, float and long double

What is the Output of following Code?
#include<stdio.h>
main()
{
int a=35, b=15, c=25,d,e;
d = a > c > b ;
e = c > b > a – 30 ;
printf(“%d,%d”,d,e);
}

  1. 0,0
  2. 1,1
  3. 1,0
  4. 0,1

Answer :

Ans : 1; Relational operators having equal priority, hence the order of evaluation from left to right side

C Technical Interview Questions on Operators – 4

Share this