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 );
}
|
||||||||||
What is the value of I that will be printed as output.
auto int I;
void
main( ) { printf( “%d”, I ); }
|
|||||||||||
What will be printed for the following program:
void main( ) {
int I = 10;
float j = 20, k;
printf( “%d”, sizeof( k = I + j ) );
}
|
|||||||||||
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");
}
}
|
|||||||||||
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);
}
|
|||||||||||
The
correct output of the following program is:
void main( ){
int i=5, j=10;
i=i&=j&&10;
printf(
"%d %d", i, j );
}
|
|||||||||||
The
correct output of the following program is:
void main( ){
static
int i;
while(
i<=10 ) (i>2)? i++ : i--;
printf(
"%d", i );
}
|
|||||||||||
What will be the output of the following program?
void main( ){
char str[ ]="%d\n";
str[1]
= 'c';
printf(
str, 97 );
}
|
|||||||||||
The correct out put for the following program is:
void main(
){
unsigned
int i=65000;
while(
i++!=0);
printf(
"%d", i );
}
|
|||||||||||
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" );
}
|
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
|
c
|
Global variable can’t be declared to be of the auto
storage class.
|
|
e
|
Implicit type conversion causes the variable ‘I’ to be
promoted to float. And the size of float value is 4 bytes.
|
|
d
|
Switch statements can be applied only to integral
types. The message is Compiler Error: switch expression not integral
|
|
a
|
& (address of ) operator cannot be applied on
register variables.
|
|
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
|
|
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
|
|
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’.
|
|
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
|
|
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.
|
No comments :
Post a Comment