II-50 Programming Concepts
The syntax of shift left operator is as follows:
Variable << number of bits to shift left.
The difference between shift right and shift left operator is as follows:
1. The shift right operator is used to divide the number by 2.
2. The shift left operator is used to multiply the number by 2.
Example:
Value of i Execution of Each Statement Final Value of i
i = 4 00000100 4
I =i<<1 00001000 8
i =i >> 1 00000010 2
i = i >> 2 00000001 1
32. Which  binary  shifting  is  equivalent to  multiplying  an  unsigned number by  2: right 
shifting by 1 or left sifting by 1?
Ans: Multiplying an unsigned number by 2 is equivalent to left shifting an unsigned number
by 1 is the correct option. This can be verified from the following example:
void main()
{
unsigned int a=8,b=1;
printf("%d",a<<b);
}
OUTPUT:
16
33. What is the equivalent expression for x&3?
Ans: The equivalent expression for x&3 is x%4.
34. What is the result of expression (23*2) % (int) 5. 5?
Ans: 1
Explanation: As per precedence of operators multiplication of 23 and 2 is performed first, result of
which is 46. Floating number 5.5 is converted to 5 due to type casting used in the expression. Ultimately,
result of 46%5 is 1. Modulus operator provides remainder.
35. What is the result of 16>> 2?
Ans: 4
Explanation: Number 16 is shifted two bits right. This is as good as 16 is divided first by two and then
result 8 is again divided by 2 whose result is 4.
M03_ITL-ESL4791_02_SE_C03.indd 50 12/22/2012 5:00:08 PM
Operators and Expressions II-51
36. What is the output of the following program?
void main()
{
int a=16,b=4;
clrscr();
printf("%d",a<<a/b-2;
}
OUTPUT:
64
Explanat ion:  In the above program a/b 2 works out to be 2. As per precedence of operators, divi-
sion operator is performed first and then subtraction. Hence, a is shifted right two bits and, therefore,
result is 64.
37. What is the result of 5&&2?
Ans: 1
Explanation: Logical ANDing between 5 and 2 is 1. Hence, the result is 1.
Multiple-choice Questions
Examples on Arithmetic Operators
1. What is the remainder of 9% 10 ?
(a) 5 (b) 2 (c) 1 (d) 9
2. What is the result of the expression ((10*2)*(10/5)%11)?
(a) 7 (b) 10 (c) 8 (d) None of them
3. What is the result of expression (float)(12/4) * (int) 5. 3 ?
(a) 15.0000000 (b) 1 (c) 3 (d) None of them
4. What is the result of 4|2?
(a) 1 (b) 6 (c) 2 (d) 0
5. Which of the following bracket is suitable for evaluation of arithmetic operations ?
(a) [ ] (b) { } (c) ( )  (d) None of the above
6. Multiplication (*) and division( / ) operators have priority than addition (+) operator.
(a) Lower (b) Higher (c) Similar
Examples on Logical Operators
7. What is the result of 10&&4?
(a) 0 (b) 1 (c) 2 (d) 5
8. The && operator is used to .
(a) Compare two numeric value (b) Compare two float values
(c) Compare two Boolean values (d) None of the above
M03_ITL-ESL4791_02_SE_C03.indd 51 12/22/2012 5:00:08 PM
II-52 Programming Concepts
Examples on Bitwise Operators
9. What is the result of 4 << 2?
(a) 8 (b) 16 (c) 2 (d) 0
10. The associativity of bitwise operators is .
(a) Right to left (b) Left to right (c) Both (a) and (b) (d) None of the above
Examples on Unary, Increment and Decrement Operator
11. The associatively of operators unary minus, increment and decrement is .
(a) Right to left (b) Left to right (c) Both (a) (b) (d) None of them
12. What is the result of the following program?
void main()
{
int a,x=15,y=10;
clrscr();
a=--x*y++;
printf(" %d",a);
}
(a) 140 (b) 200 (c) 380 (d) 210
13. What will be the output of the following program?
#include <stdio.h>
#include <conio.h>
void main()
{
int ans=2;
int m=10;
int k;
k=!((ans<2) || (m>2));
printf(" %d",k);
}
(a) 1 (b) 0 (c) 2 (d) 4
14. What will be the output of the following program?
#include <stdio.h>
#include <conio.h>
void main()
{
int m,j=3,k;
m=2*j/2;
M03_ITL-ESL4791_02_SE_C03.indd 52 12/22/2012 5:00:08 PM
Operators and Expressions II-53
k=2*(j/2);
clrscr();
printf(" m=%d k=%d",m,k);
}
(a) m = 3 k = 2 (b) m = 3 k = 3 (c) m = 2 k = 3 (d) m = 2 k = 2
15. What will be the value of x, y and z after execution of the following program?
#include <stdio.h>
#include <conio.h>
void main()
{
int x,y,z;
y=2;
x=2;
x=2*(y++);
z=2*(++y);
printf(" x=%d y=%d z=%d",x,y,z);
}
(a) x = 4 y = 4 z = 8 (b) x = 6 y = 4 z = 8 (c) x = 2 y = 4 z = 8 (d) x = 4 y = 4 z = 4
16. What will be the value of x after execution of the following program?
#include <stdio.h>
#include <conio.h>
void main()
{
int x=!0*0;
}
(a) 0 (b) 1 (c) 10 (d) None of the above
17. What will be the value of k after execution of the following program?
void main()
{
int b,k=8;
b=(k++ - k++-k++,k++);
printf(" %d",k);
}
(a) 11 (b) 12 (c) 7 (d) 9
M03_ITL-ESL4791_02_SE_C03.indd 53 12/22/2012 5:00:08 PM
II-54 Programming Concepts
18. What will be the output of the following program?
void main()
{
int i=1,j=2,k=3;
clrscr();
printf("%d",!((j+k)>(i+5)));
}
(a) 0 (b) 1 (c) −1 (d) 2
19. What will be the value of j after execution?
void main()
{
float j=8,k=5; j*=k*+3.145;
clrscr();
printf("j=%g",j);
}
(a) 125.8 (b) 124.9 (c) 124.8 (d) 0
20. What will be the value of y?
(a) void main()
{
float y;
y=22/8*(3.145+2)*8/5;
clrscr();
printf("y=%g",y);
}
(a) 16.464 (b) 16.064
(c) 16 (d) 0
21. In C language, the compound statement a* = a + 2; means .
(a) a = a*(a + 2); (b) a = a*a + 2; (c) a = a + a*2; (d) a = a + 2*a;
22. In C language, the compound statement a%=5; means .
(a) a = a%5; (b) a = 5%a; (c) a = a*a%5; (d) a = a%5/5;
23. In C language, the statement a|b; means .
(a) AND operation between a and b
(b) OR operation between a and b
(c) NOT operation between a and b
(d) EXOR operation between a and b
M03_ITL-ESL4791_02_SE_C03.indd 54 12/22/2012 5:00:08 PM
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset