C - Control Flow Constructions
C - Control Flow Constructions
51. int a = 0, b = 2;
if ( a = 0) b = 0;
else b *=10;
what is the value of b?
if ( a = 0) b = 0;
else b *=10;
what is the value of b?
- 0
- 20
- 2
- none
52. int x = 2, y = 2 , z = 1;
what is the value of x after the following statements ?
if (x = y%2) z +=10;
else z +=20;
what is the value of x after the following statements ?
if (x = y%2) z +=10;
else z +=20;
- 0
- 2
- 1
- none
53. What is the result?
main ( )
{
char c =-64; int i =-32;
unsigned int u =-16;
if (c>i)
{
printf ("pass1");
if (c>u) printf ("pass2");
else printf ("Fail2");}
else printf ("Fail");
if (i<u) printf ("pass2");
else printf ("Fail2");
}
main ( )
{
char c =-64; int i =-32;
unsigned int u =-16;
if (c>i)
{
printf ("pass1");
if (c>u) printf ("pass2");
else printf ("Fail2");}
else printf ("Fail");
if (i<u) printf ("pass2");
else printf ("Fail2");
}
- pass pass2
- pass 1 Fail2
- Fail pass2
- Fail Fail 2
54. How many x are printed ?
for ( i = 0, j = 10; i < j; i++, j-- --)
printf ("x");
for ( i = 0, j = 10; i < j; i++, j-- --)
printf ("x");
- 10
- 5
- 4
- none
55. What is the output of the following program ?
main ( )
{
unsigned int i;
for (i = 10; i >=0; i- -)
printf ("%d", i);
}
main ( )
{
unsigned int i;
for (i = 10; i >=0; i- -)
printf ("%d", i);
}
- prints numbers 10 to 0
- prints numbers 10 to 1
- prints numbers 10 to-1
- goes into infinite loop
56. unsigned char c;
for ( c = 0; c! = 256; c + 2)
printf ("%d", c);
How many times the loop is executed ?
for ( c = 0; c! = 256; c + 2)
printf ("%d", c);
How many times the loop is executed ?
- 127
- 128
- 256
- infinitely
57. For the following code how many times the printf ( ) function is executed ?
int i , j ;
for ( i =0 ; i <=10; i++);
for ( j = 0; j<=10; j++);
printf ( "i = %d, j = %d\n", i , j);
int i , j ;
for ( i =0 ; i <=10; i++);
for ( j = 0; j<=10; j++);
printf ( "i = %d, j = %d\n", i , j);
- 121
- 11
- 10
- none of the above
58. What is output of the following code ?
main ( )
{
int i = 3;
while ( i - - )
{
int i = 100;
i - - ;
printf ("%d. . " , i );
}
}
main ( )
{
int i = 3;
while ( i - - )
{
int i = 100;
i - - ;
printf ("%d. . " , i );
}
}
- Infinite loop
- Error
- 99..99..99..
- 3..2..1..
59. What will be the output of the following code ?
{
ch = 'A';
while (ch<='F')
{
switch (ch)
{
case 'A' : case 'B': case 'C': case 'D' : ch ++; continue;
case 'E" : case 'F' : ch ++;
}
putchar (ch) ;
}
}
{
ch = 'A';
while (ch<='F')
{
switch (ch)
{
case 'A' : case 'B': case 'C': case 'D' : ch ++; continue;
case 'E" : case 'F' : ch ++;
}
putchar (ch) ;
}
}
- ABCDEF
- EFG
- FG
- Error
60. main ( )
{
int , ones,twos, threes, others; int c;
ones =twos = threes = others = 0 ;
while ( ( c = getchar ( ) ) !_ '\n')
{
switch (c)
{
case ' 1 ' : ++ ones;
case ' 2 ' : ++twos;
case '3' : ++ threes;
break;
default : ++others;
break;
}
}
printf ( "%d%d", ones, others );
}
If the input is "lalblc" what is the output ?
{
int , ones,twos, threes, others; int c;
ones =twos = threes = others = 0 ;
while ( ( c = getchar ( ) ) !_ '\n')
{
switch (c)
{
case ' 1 ' : ++ ones;
case ' 2 ' : ++twos;
case '3' : ++ threes;
break;
default : ++others;
break;
}
}
printf ( "%d%d", ones, others );
}
If the input is "lalblc" what is the output ?
- 13
- 34
- 33
- 31