You are on page 1of 7

Chapter – 2

Expression, Operators & their Precedence

1. Which of the following C expression is equivalent to the algebraic expression :


3x2 +3(4x+6).

1) 3*x*x+3*(4x+6) 2) 3*x*x+3(4x+6)
3) 3*x*x+3(4*x+6) 4) 3*x*x+3*(4*x+6)

2. In the following expression which operation is performed first?


Expression: a=3/2+9*6/4-7+2.4/8

1) 3/2 2) 9*6 3) 6/4 4) 2+9

3. Which type is not available in operators?

1) unary 2) binary 3) ternary 4) nnary

4. Which of the following are unary operators?

i) %(modulus) ii) =(assignment)


iii) –(subtraction) iv) / (division)

5. How many ternary operators are available in C?

1) 1 2) 2 3) 5 4) Compiler dependent

6. What is negation of operator <?

1) ! 2) > 3) !< 4) >=

7. Which is invalid type of operator?

1) Bitwise 2) Relational 3) Logical 4) Saving

8. Which is correct statement?

1) && checks 2nd condition only if 1st condition is false


2) && checks 2nd condition only if 1st condition is true
3) || checks 2nd condition only if 1st condition is true
4) && and || both check 2nd condition irrespective of 1st condition answer

9. Which can not be used as assignment operator?

1) %= 2) != 3) ^= 4) &=
10. How to store value of x in y?

1) x=y; 2) x= =y; 3) y=x; 4) y= =x;

11. Which is not a operator in C?

1) ^ 2) ~ 3) sizeof 4) $

12. Which unary operator changes operand?

1) ! 2) ~ 3) - 4) - -

13. Find invalid bitwise operator

1) ^ 2) >> 3) ~ 4) &&

14. Which operator does not work with float?

1) / 2) % 3) ++ 4) !

15. What is not allowed?

1) + k 2) ++ k 3) +++ k 4) ++++ k

16. Which is correct precedence order of binary operators?


(descending order of priority)

1) Assignment, Relational, Logical, Arithmetic


2) Relational, Arithmetic, Logical, Assignment
3) Arithmetic, Relational, Logical, Assignment
4) Arithmetic, Logical, Relational, Assignment

17. Which operator does not check 2nd condition if 1st condition is false?

1) || 2) >> 3) & 4) &&

18. What is associativity for comma operator?

1) Left to Left 2) Left to Right


3) Right to Left 4) Right to Right

19. Which condition can result into true?

1) x>y && x<y 2) x>=y && y>x


3) x!=y && x>y 4) x= =y && x>y
20. Which is not a operator in C?

1) -> 2) .* 3) != 4) +=

21. void main( )


{ float a=5,b=2;
printf(“%f”, a%b*2);
}

1) 2.0 2) 0.5 3) 1.0 4) Compilation error

22. Which statement will generate an error?

1) a=b>c ? b : c; 2) (b>c) ? a=b : a=c;


3) (b>c) ? a=b : (a=c); 4) (b>c) ? (a=b) : (a=c);

23. void main( )


{ int no 1 =0;
printf(“%d”, 5/no 1);
}

1) 5 2) Compilation error
3) 32767 4) Runtime error

24. void main( )


{
printf(“%d”, 5/0 );
}

1) 5 2) Compilation error
3) 32767 4) Runtime error

25. void main( )


{ int x=1, y=2, z=6;
x+=x+y*z=8;
printf(“ %d”, x);
}

1) 18 2) 2 3) 14 4) Compilation error

26. void main( )


{ int x=1, y=2, z=3;
printf(“ %d %d %d”, ++x, x+y, z);
}

1) 1 3 3 2) 2 3 3 3) 2 4 3 4) 1 4 3
27. void main( )
{ int x=2;
float f1=1.0, f2=2.0, sum;
sum=x*f1+f2/x+f1*f2;
printf(“%f ”, sum);
}

1) 5.000000 2) 6.000000
3) 1.500000 4) Compilation error

28. void main( )


{ int v=-5, w=0, x=4;
printf(“%d”, w || v || x&&w);
}

1) 1 2) 0 3) 5 4) Garbage value is printed

29. void main( )


{ int s1 = 1, s2=4;
printf(“%d”, (s1&s2)?5:10 );
}

1) 10 2) 5 3) 0 4) 1
30. void main( ).
{ int i=2, j=3, k=0, m=0 ;
float a=1, b=2;
k=i/j *k;
m=j/i*j;
a=i*/j*j;
b=i*j/k;
printf(“%d %d %f %f ”, k, m, a, b);
}

1) 0 3 0.000000 0.000000 2) 2 3 0.000000 2.000000


3) 0 3 0.000000 2.000000 4) Error

31. void main( )


{ int xx=3*(5 +1)/(2-2*10);
printf(“%d”, xx);
}

1) 1 2) -1 3) 0 4 Divide by zero error

32. void main( )


{ int x=32767, y=9;
x=x+y;
printf(“%d”, x);
}

1) 32776 2) -32776 3) -32760 4) Garbage value

33) void main( )


{ int u1; float u2;
printf(“%d”, sizeof(u2+sizeof(u1)));
}

1) 8 2) 4 3) 6 4) Compilation Error

34. void main( )


{ int a=2, b, c,d;
b=c=5;
d=++a- --b*c%b;
printf(“d”, d);
}

1) 3 2) 2 3) -1 4) Error:Lvalue required

35. void main( )


{ char b='C ', c='B';
printf(“%c”, c+b-36);
}

1) 133 2) A 3) a 4) Garbage ASCII character

36. void main( )


{ char c1='I', c2='2';
int sum=c1+c2;
printf(“%c %d”, sum, sum);
}

1) c 99 2) C 99 3) 3 51 4) 3 garbage

37. void main( )


{ int product;
char ch='CH';
product(“%d”, product);
}

1) 99 2) 67 3) Garbage 4) Error:Character constant too long


38. void main( )
{ int p=1, q=2, r=3;
float p=1.0, q=2.0, r=3.0;
printf(“%d %d %f”, p, q, r);
}
1) 1 2 3 2) 1.0 2.0 3.0 3) 1 2 3.0 4) Error
39. void main( )
{ int p=10;
printf(“%d %d %d”, p--, ++p, p--);
}

1) 10 9 10 2) 10 10 10 3) 9 11 10 4) 10 10 11

40. void main( )


{ int p=10;
printf(“%d %d %d”, --p, --p, --p);
}

1) 10 9 8 2) 8 8 8 3) 9 8 7 4) 7 8 9

42. void main( )


{ char ch=20;
printf(“%d %d”, ch>>4, ch <<2 );
}

1) 180 10 2) 5 40 3) 1 80 4) 80 1

43. void main( )


{ int a=5, b=2;
printf(“%d %f %f”, a/b, (float)a/b,a/(float)b );
}

1) 2 2.000000 2.500000 2) 2 2.5 2.5


3) 2 2.500000 2.500000 4) none

44. void main( )


{ int p=5, x;
x=++p*p++;
printf(“%d”, x);
}

1) 49 2) 42 3) 36 4) 30

45. void main( )


{ int p=4;
printf(“%d”, ++p*p++*++p);
}

1) 175 2) 252 3) 216 4) none

46. void main( )


{ int i=1, j=0, k=i--&&++j||--i;
printf(“%d %d %d”, i, j, k);
}

1) 0 1 1 2) 1 1 1 3) 0 1 0 4) none

47. void main( )


{ int i=20, j=30;
i^=j;
j^=i;
i^=j;
printf(“%d, %d”, i, j);
}

1) 20,20 2) 20,30 3) 0,0 4) 30,20

48. void main( )


{ unsigned long val=0x12345678;
printf(“0x%x”,(val>>16) | ((val & 0xffff)<<16));
}

1) 0x12345678 2) 0x1234 3) 0x87654321 4) 0x56781234

49. void main( )


{ char ch=-3;
printf(“%d %d %d”, -ch, -ch+1, !ch );
}

1) 3 -3 1 2) 3 4 0 3) 3 132 0 4) -3 132 1

50. void main( )


{
printf(“%d”, 32>>2 );
}

1) 8 2) 30 3) 128 4) 64

You might also like