C-Control Structure Question and Answer
C-Control Structure Question and Answer
31. Find the output
void main ( )
{
enum e{red, green};
enum e ee=red;
switch (ee)
{
case red:
printf("red");
break;
case green:
printf("green");
break;
}
}
void main ( )
{
enum e{red, green};
enum e ee=red;
switch (ee)
{
case red:
printf("red");
break;
case green:
printf("green");
break;
}
}
- red
- Error: constant expression required
- green
- Enum can't be a part of structure
32. Find the output
void main ( )
{
int ch=2;
switch (ch++)
{
case 1:
printf("%d", ++ch);
case 2:
printf("%d", ++ch);
default:
printf("%d", ++ch);
}
}
void main ( )
{
int ch=2;
switch (ch++)
{
case 1:
printf("%d", ++ch);
case 2:
printf("%d", ++ch);
default:
printf("%d", ++ch);
}
}
- 4
- 3
- 45
- None of these
33. Find the output
void main ( )
int a=2, b=3;
do
{
a=a^b;
a=b^a;
a=a^b;
continue;
}
while (a==3);
printf("%d%d", a, b);
}
void main ( )
int a=2, b=3;
do
{
a=a^b;
a=b^a;
a=a^b;
continue;
}
while (a==3);
printf("%d%d", a, b);
}
- 2 3
- 3 2
- Infinite loop
- None of these
34. Find the output
void main ( )
{
int a=5;
while (a!=1)
{
goto xx;
xx: printf("%d", a--);
}
}
void main ( )
{
int a=5;
while (a!=1)
{
goto xx;
xx: printf("%d", a--);
}
}
- 5
- 5 4 3 2 1
- 5 4 3 2
- Compilation error
35. Find the output.
void main ( )
{
int i=5;
if (i==5)
return;
else
printf("%d",i);
printf("bye");
}
void main ( )
{
int i=5;
if (i==5)
return;
else
printf("%d",i);
printf("bye");
}
- bye
- 5
- No output
- Compilation error
36. Find the output
void main {
float f=3.2;
switch (f!=3.2)
{
default:
printf("no result");
case 0:
printf ("false");
case 1;
printf("true");
break;
}
}
void main {
float f=3.2;
switch (f!=3.2)
{
default:
printf("no result");
case 0:
printf ("false");
case 1;
printf("true");
break;
}
}
- true
- no result true
- no result false true
- Compilation error
37. 'continue'statement is used in
- Selective control structure
- Loop control structure
- Both a and b
- None of these
38. Find the output
void main ( )
{
float f=2.5;
if (f==2.5)
printf ("right");
else
prrintf ("wrong");
}
void main ( )
{
float f=2.5;
if (f==2.5)
printf ("right");
else
prrintf ("wrong");
}
- right
- wrong
- Depends on memory model
- None of these
39. Find the output
void main ( )
{
int i=1, j=2, k=3;
if (i==1)
if (j==2)
if (k==3)
{
printf("ok");
break
}
else
printf("continue");
printf("bye");
}
void main ( )
{
int i=1, j=2, k=3;
if (i==1)
if (j==2)
if (k==3)
{
printf("ok");
break
}
else
printf("continue");
printf("bye");
}
- ok
- okbye
- Misplaced break
- None of these
40. Find the output
void main ( )
{
int i=5;
switch (i)
{
static int i;
i=3;
i=i*i;
case 3:
i=i+i;
case 5:
i=i+i;
default :
i=i+i;
printf("%d", i);
}
printf ('%d", i);
}
void main ( )
{
int i=5;
switch (i)
{
static int i;
i=3;
i=i*i;
case 3:
i=i+i;
case 5:
i=i+i;
default :
i=i+i;
printf("%d", i);
}
printf ('%d", i);
}
- 365
- 205
- 05
- 55