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>
int main(void)
{
int x=5 , y=2;
printf(“%d”, x/y);
return 0;
}

  1. 2.5
  2. 2.0
  3. 2
  4. 0

Answer :

Ans : 3; We are printing only integer part of the result.

What is the Output of following Code?
#include<stdio.h>
int main(void)
{
int x=5 , y=2;
int z = (float)x/y ;
printf(“%f”, z);
return 0;
}

  1. 2.5
  2. 2
  3. 0.000000
  4. 2.000000

Answer :

Ans : 3; We cannot assign a float value directly into integer variable. it stores default value of float.

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

  1. -3
  2. -5
  3. -2
  4. -4

Answer :

Ans : 2; Evaluate expression according to priority of arithmetic operators

What is the Output of following Code?
#include<stdio.h>
int main(void)
{
int x=5 , y=2;
float z = x%y ;
printf(“%f”, z);
return 0;
}

  1. 0.000000
  2. 1
  3. Compiler error
  4. 1.000000

Answer :

Ans : 4; The result of x%y is 1 and that will be stored as 1.000000.

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

  1. 0, -6
  2. compiler error
  3. 0, garbage value
  4. -6, 0

Answer :

Ans : 2; L value required in both the expressions.

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. 20
  2. 10
  3. compile time error
  4. garbage value

Answer :

Ans : 3; Error : L value required : we cannot assign b variable to 20.

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

  1. 10 , 10
  2. 10 , 11
  3. 11 , 10
  4. 11 , 11

Answer :

Ans : 3; Post increment increase the value after substitution in expression, hence b value is 10.

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

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

Answer :

Ans : 2; if condition is true(x+1), it executes expression1(–x)

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

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

Answer :

Ans : 1; Both the conditions 10>20  and  20>30 are false, hence expression2 value(30) will be printed

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

  1. 2
  2. 4
  3. 1
  4. compile time error

Answer :

Ans : 1; The value of !5.6 is 0, and the size of 0 is 2 bytes

C Technical Interview Questions – Operators – 2

Share this