C-Control Structure Question and Answer
C-Control Structure Question and Answer
11. Find the output
void main ( )
char x='A';
switch (x)
{
if (x==A)
{
printf("tomtom");
}
else
{
printf("tom")
default:printf("harry");
}
}
}
void main ( )
char x='A';
switch (x)
{
if (x==A)
{
printf("tomtom");
}
else
{
printf("tom")
default:printf("harry");
}
}
}
- tomtom
- harry
- tomharry
- Compilation error
12. Find the output
void main ( )
{
if (printf("hello");
else
printf ("hai");
}
void main ( )
{
if (printf("hello");
else
printf ("hai");
}
- hello
- hai
- Compilation error
- None of these
13. Find the output
void main ( )
{
switch (2)
{
case 2:
printf("no");
continue;
case 1:
printf("output");
default :
printf ("continue");
}
void main ( )
{
switch (2)
{
case 2:
printf("no");
continue;
case 1:
printf("output");
default :
printf ("continue");
}
- no
- nononono....
- nooutputcontinue
- None of these
14. Which of the following is/are true for nested if
I. It can only test for equality.
II. Conditions may be repeatred for number of times.
III. it can evaluate relational or logical expressions.
IV. Character constants are automatically converted to integers.
I. It can only test for equality.
II. Conditions may be repeatred for number of times.
III. it can evaluate relational or logical expressions.
IV. Character constants are automatically converted to integers.
- I & II
- I. II & III
- II, III & IV
- All o the above
15. Find the output.
void main ( )
{
int i=2;
i++;
if (i=4)
printf("i=4");
else
printf("i=3");
}
void main ( )
{
int i=2;
i++;
if (i=4)
printf("i=4");
else
printf("i=3");
}
- i=3
- i=4
- Garbage value
- None of these
16. Find the output
void main ( )
{
int x, y;
printf("%d", x=(y=5, y*y));
}
void main ( )
{
int x, y;
printf("%d", x=(y=5, y*y));
}
- 5
- 25
- Invalid expressio
- Compilation error
17. Find the output
void main ( )
{
char a='H';
switch (a)
{
case 'H':
printf("%c", 'H');
case 'E":
printf("%c", 'E');
case 'L':
printf("%c", 'L')}
case 'O':
printf ("%c", 'O');
}
}
void main ( )
{
char a='H';
switch (a)
{
case 'H':
printf("%c", 'H');
case 'E":
printf("%c", 'E');
case 'L':
printf("%c", 'L')}
case 'O':
printf ("%c", 'O');
}
}
- HELLO
- HEL
- HELO
- Compilation error
18. Which of the following is true about the switch statement ?
- The default statement is necessary
- The break statement is compulsory
- The statements associated with a case do not form a block
- Switch without case is worthless
19. Find the output
void main ( )
{
int x=1, y=2, z=3, result;
result=(x+1?y>=2?z>3?1:2:3:4);
printf("%d",result);
}
void main ( )
{
int x=1, y=2, z=3, result;
result=(x+1?y>=2?z>3?1:2:3:4);
printf("%d",result);
}
- 1
- 2
- 3
- 4
20. Find the output
void main ( )
{
it (6>3)
{
printf("hello");
break;
}
else
printf("bye");
}
void main ( )
{
it (6>3)
{
printf("hello");
break;
}
else
printf("bye");
}
- hello
- bye
- Compilation error
- None of these