Ans. 22: 024 0xA0h
Why?
We are given that:
sc = (012)8 = (000 001 010)2
sv = (0x28)16 = (0000 0010 1000)2
So, sc << 1 = 000 001 010 = 0128
= (000 010 100)2 = 0248 (after left shift)
Similarly, sv << 2 = (0000 0010 1000) = 028h
So, sv << 1 = (0000 0101 0000) = 050h
And sv << 1 = (0000 1010 0000) = 0(10)0h = 0A0h
So, the output is (024 0xA0h) = (20d 160d)
NOTE
In shifting, bits are lost, whereas in rotation, bits are not lost (i.e., LSBs become MSBs
and vice versa).
Q23.
How many times is the following loop executed?
for (l=0; ++l <10; l++)
(a) 10 times
(b) 9 times
(c) 5 times
(d) none of the above
Ans. 23:
9 times
l
++l
execution
0
1<10
1
1
2<10
2
2
3<10
3
3
4<10
4
4
5<10
5
5
6<10
6
6
7<10
7
7
8<10
8
8
9<10
9 times.
9
10<10 (is false).
Q24.
Give the output of the following program:
main( )
{
int m, n;
m = 14;
n = 15;
printf(“m & n = %d”, m & n);
}
Ans. 24:
Now, m= 14 d = (1110)
2
n = 15d = (1111)
2
So, 1110
& 1111
1110
And 1110 = 0 * 2
0
+ 1 * 2
1
+ 1 * 2
2
+ 1 * 2
3
= 0 + 2 + 4 + 8 = 14
10
Q25.
Give the output of the following program:
#include
#include
main( )
{
int i = 7;
int res;
clrscr( );
res = i++ * i++;
cout << “Result is: “ << res;
getch( );
}
Ans. 25:
49
Q26.
Give the output of the following program:
main( )
{
int i =7;
int res;
res = ++i * ++i;
printf(“%d”, res);
}
Ans. 26:
81 (as unary has higher precedence, i is incremented twice first and then multiplied.
Q27.
Give the output of the following program:
void main( )
{
int i = 7;
int res;
res = i++ * ++i;
printf(“%d”, res);
}
Ans. 27: 64
(unary has higher precedence, and first i is incremented once (i.e., 8 and then 8 * 8
gives 64).
Q28.
Give the output of the following program:
#include
#include
#define value 1+2
void main( )
{
printf(“Value is %d”, value);
printf(“Value of expressions are %d %d:”, value/value, value * 3);
}
Ans. 28:
The value is 3.
Value of expressions are 5 7
Why?
value/ value = 1+ 2/1 + 2, 1+2*3
= 1+2+2, 1+6
= 5, 7
Q29.
Differentiate between a constant and a variable.
Ans. 29.
The following table gives the differences:
Constant
Variable
A constant does not change during the execution of the program.
A variable varies during the execution of the program.
A constant is a quantity that is fixed. It may be numbers,
characters, or strings.
A variable is the named memory location where a constant is
stored.
A constant does not store in memory.
A variable stores in memory.
For example, 7.8, 3.1417 are constants.
For example, u, v are variables.
Q30.
Distinguish between the getchar( ) and scanf( ) functions of C.
Ans. 30.
The following table gives the differences:
10>10>10>10>10>10>10>10>10>10> Do'stlaringiz bilan baham: |