C Programming and Problem Solving Questions and Answers 261 to 270

C Programming and Problem Solving

Questions 261 to 270



261.
The output of the following program is:
void main( ){
int a=2,*f1,*f2;
f1=f2=&a;
*f2+=*f2+=a+=2.5;
printf( "\n%d %d %d", a, *f1, *f2 );
}
(a)
16 16 16
(b)
4 9 18
(c)
4 6 12
(d)
12 12 12
(e)
18 18 18.
262.
What is the value of I that will be printed as output.
auto int I;
void main( ) { printf( “%d”, I ); }
(a)
Garbage
(b)
0
(c)
Compile time Error
(d)
Runtime Error
(e)
No error but compiler dependent.
263.
What will be printed for the following program:
void main( ) {
int I = 10;
float j = 20, k;
printf( “%d”, sizeof( k = I + j ) );
}
(a)
Compile time error
(b)
0
(c)
1
(d)
2
(e)
4.
264.
What will be printed as the output for the following  program:
void main( ){
float i=1.5;
switch(i){
case 1:               printf("1");
case 2:               printf("2");
default :      printf("0");
}
}
(a)
    1
(b)
120
(c)
    0
(d)
Compile time error
(e)
Runtime error.
265.
The output for the following program is:
void main( ){
register int a=2;
printf("Address of a = %d",&a);
printf("Value of a   = %d",a);
}
(a)
Compile time error
(b)
Runtime error
(c)
Address of a and 2
(d)
A negative value and 2
(e)
2 2.
266.
The correct output of the following program is:
void main( ){
int i=5, j=10;
i=i&=j&&10;
printf( "%d %d", i, j );
}
(a)
5 10
(b)
1 10
(c)
5 5
(d)
10 10
(e)
1 1.
267.
The correct output of the following program is:
void main( ){
static int i;
while( i<=10 ) (i>2)? i++ : i--;
printf( "%d", i );
}
(a)
11
(b)
12
(c)
32767
(d)
-32768
(e)
Syntax error.
268.
What will be the output of the following program?
void main( ){
char str[ ]="%d\n";
str[1] = 'c';
printf( str, 97 );
}
(a)
Syntax Error
(b)
%d
(c)
%c
(d)
c
(e)
a.
269.
The correct out put for the following program is:
void main( ){
unsigned int i=65000;
while( i++!=0);
printf( "%d", i );
}
(a)
Infinite loop
(b)
Syntax error
(c)
 1
(d)
 0
(e)
-1.
270.
The output of the following program is:
void main( ){
int i;
char str[]="\0";
if( printf( "%s\n", str) ) printf( "Nothing printed \n" );
else printf( "Something printed \n" );
}
(a)
Syntax error
(b)
Runtime termination as abnormal program termination
(c)
Something printed
(d)
Nothing printed
(e)
Something printed \n.



Answers



261.
a
f1 and f2 both refer to the same memory location a. So changes through f1 and f2 ultimately affects only the value of a
262.
c
Global variable can’t be declared to be of the auto storage class.
263.
e
Implicit type conversion causes the variable ‘I’ to be promoted to float. And the size of float value is 4 bytes.
264.
d
Switch statements can be applied only to integral types. The message is Compiler Error: switch expression not integral
265.
a
& (address of ) operator cannot be applied on register variables.
266.
b
The expression can be written as i=(i&=(j&&10)); The inner expression (j&&10) evaluates to 1 because j==10. i is 5. i = 5&1 is 1. Hence the result
267.
c
Since i is static it is initialized to 0. Inside the while loop the conditional operator evaluates to false, executing i--. This continues till the integer value rotates to positive value (32767). The while condition becomes false and hence, comes out of the while loop, printing the i value
268.
e
Due to the assignment str[1] = ‘c’ the string becomes, “%c\n”. Since this string becomes the format string for printf and ASCII value of 97 is ‘a’.
269.
c
Note the semicolon after the while statement. When the value of i becomes 0 it comes out of while loop. Due to post-increment on i the value of i while printing is 1
270.
d
printf( ) returns how many characters does it print. Hence printing a null character returns 1 which makes the ‘if statement’ true, hence "Nothing printed" is the output.



<< Prev 1...  2...  3...  4...  5...  6...  7...  8...  9...  10...  11... 12...  13...  14...  15...  16...  17...  18...  19...  20...  21...  22...  23...  24...  25...  26...  27...  28...  29...  30...  31...  32...  33...  34...  35...  36...  Next >>


No comments :

What you think about these Questions and Answers ? Let me know in comments.

Post a Comment