The document contains 40 multiple choice questions about operators, data types, precedence, associativity, conditional and logical operators, control flow statements like if-else and switch case in C programming language.
The document contains 40 multiple choice questions about operators, data types, precedence, associativity, conditional and logical operators, control flow statements like if-else and switch case in C programming language.
The document contains 40 multiple choice questions about operators, data types, precedence, associativity, conditional and logical operators, control flow statements like if-else and switch case in C programming language.
The document contains 40 multiple choice questions about operators, data types, precedence, associativity, conditional and logical operators, control flow statements like if-else and switch case in C programming language.
Download as DOCX, PDF, TXT or read online from Scribd
Download as docx, pdf, or txt
You are on page 1of 8
MCQs’ for Unit 2
1. Which operator among the following has the highest precedence?
a. Logical Operators b. Arithmetic Operators c. Unary Operators d. Bitwise Operators 2. What will be the output of the following code? # include<stdio.h> void main() { float a=7,b; b=a/2; printf(“%0.2f”,b); } a. 3.50 b. 3.5 c. 3.500000 d. 3.000000 3. What will be the output of the following code? # include<stdio.h> void main() { float b; b=3.0%5; printf(“%f”,b); } a. 3.0 b. 3 c. Error d. 3.000000 4. Which operator among the following does not work for the float values? a. % b. * c. + d. – 5. What will be the output of the following code? # include<stdio.h> void main() { int a=7; float b; b=(float) a/2; printf(“%f”,b); } a. 3.500000 b. 3.000000 c. 3.0 d. 3.5 6. What will be the effect of the left shift on the magnitude of value? a. Increase b. Decrease c. No change d. None of the above 7. _______ defines the order of evaluation when operators have the same precedence. a. Priority b. Precedence c. Associativity d. None of the above 8. sizeof() operator returns the size of an operand in _____. a. Bits b. Nibble c. Bytes d. None 9. Which of the following is the correct way of using type casting? a. c=(int)a/b; b. c=a(int)/b; c. c=int a/b; d. None 10. If statement is a __________ statement. a. One-way decision b. Multi-way decision c. Two way decision d. Loop construct 11. The two different ways to implement a multiway selection in C are: a. Simple if and if-else b. if-else and nested if-else c. else-if ladder and switch d. None 12. C provides _________ as a convenient alternative to the traditional if-else for two way selection. a. Conditional operator b. Short hand assignment c. Increment d. None 13. What will be the output of the following code? # include<stdio.h> void main() { int i=1; switch(i) { case 1:printf(“Hello”); case 2:printf(“Hi”); default:printf(“Wrong choice”); } } a. Hello b. Hi c. HelloHiWrong choice d. Wrong choice 14. What will be the output of the following code: # include<stdio.h> void main() { float a=7; int b; b=a/2; printf(“%d”,(int)b); } a. 3.500000 b. 3.5 c. 3.000000 d. 3 15. What will be the output of following code: # include<stdio.h> void main() { int a=7; float b; b=float(a/2); printf(“%f”,b); } a. 3.5 b. 3.500000 c. 3.000000 d. Error 16. What will be the output of the following code: # include<stdio.h> void main() { int a=5; if(a==5) printf(“Hello”); else printf(“Bye”); printf(“Hi”); } a. HelloHi b. Hello c. Hi d. Bye 17. What will be the output of the following code: # include<stdio.h> void main() { int a=0; if(a==0) printf(“Hello”); printf(“Hi”); else printf(“Bye); } a. Hello b. HelloHi c. Bye d. Error 18. What will be the outputof the following code: # include<stdio.h> void main() { int i=1,j=-1; if((printf(“%d”,i))<(printf(“%d”,j))) printf(“%d”,i); else printf(“%d”,j); } a. 1-11 b. 1-1-1 c. Error d. No output 19. What will be the output of the following code: # include<stdio.h> void main() { if(1) printf(“Hello”); else printf(“World”); } a. Hello b. World c. Error d. None of the above 20. What will be the output of the following code: # include<stdio.h> void main() { int x=4; printf(“%d %d %d”,x++,++x,x--); } a. 4 4 4 b. 4 4 3 c. 5 4 3 d. 5 5 4 21. The default statement is executed when: a. All the case statements are false b. One of the case is true c. One of the case is false d. None 22. Which operator among the following has the highest precedence? a. + b. – c. ( ) d. % 23. What will be the value of A^8? a. 2 b. 18 c. F d. A 24. What will be the value of 4 && 0? a. 1 b. 0 c. Error d. None of the above 25. What will be the output of the following: int x=1,y=0,z=1,a; a=x && y && ++z; printf(“%d”,z); a. 1 b. 2 c. 3 d. 0 26. What will be the value of 1’s complement of A (~A)? a. 5 b. A c. 6 d. None 27. The assignment statement ―sum=sum+i;‖ is equivalent to: a. sum=+i b. sum+=i c. sum==sum+i d. None 28. Left shift is equivalent to: a. Division by 2 b. Multiplying by 2 c. Adding 2 d. Subtracting 2 29. Which of following is not a valid assignment expression? a. y = 22; b. s = x; c. y%=6; d. z = 5 = 3; 30. In C Programming, the statement a = a+1 and a+=1 will produce same result? a. True b. False 31. What will the value of variable a? int a = 10 + 2 * 12 / (3*2) + 5; a. 31 b. 19 c. 11 d. 29 32. What will be the output of the following code: # include<stdio.h> void main() { int i=1,j=3; if(++i) printf(“%d”,i); else printf(“%d”,j); } a. 2 b. 1 c. 3 d. None of the above 33. What will be the value of c: int a=2,b=3; c=a,b; a. 2 b. 3 c. Error d. None of the above 34. What will be the output of the following code: # include<stdio.h> void main() { if(True) printf(“Hello”); else printf(“Bye”); } a. Hello b. Bye c. Error d. None of the above 35. Which statement will be true for logical AND? a. If first condition is true then only the other condition will be checked. b. If first condition is false then second condition will not be checked. c. Both a and b d. Neither a nor b 36. What will be the output of the following code: # include<stdio.h> void main() { if(0) printf(“Hello”); else printf(“Bye”); } a. Hello b. Bye c. Error d. None of the above 37. What will be the output of the following code: # include<stdio.h> float ch; switch(ch) { case 1.5:printf(“%d”,2); case 2.5:printf(“%d”,3); } a. 23 b. 2 c. Error d. None of the above 38. What will be the output of the following code: # include<stdio.h> void main() { if(printf(“%d”,2)); printf(“%d”,4); } a. 24 b. 4 c. 2 d. Error 39. What will be the value of c: a=1,b=2 c=(a,++b); printf(“%d”,c); a. 1 b. 2 c. 3 d. 0 40. What will be the output of the following code: int main() { int k=64; switch(k) { case k<64: printf(“SHIP “); break; case k>=64: printf(“BOAT “); break; default: printf(“PETROL”); } printf(“CHILLY”); } a. BOATCHILLY b. BOATPETROLCHILLY c. SHIPBOATCHILLY d. Compiler Error