C-Control Structure Question and Answer
C-Control Structure Question and Answer
91. Find the output
void main ( )
{
int x=5;
begin:
if (x)
{
printf ("%d", x);
x--;
goto begin;
}
}
void main ( )
{
int x=5;
begin:
if (x)
{
printf ("%d", x);
x--;
goto begin;
}
}
- No output
- 5
- 54321
- Garbage value
92. Find the output
#define a i++
void main ( )
{
int i=0;
if (0==a);
#define a --1
else
#define a ++i
printf ("%d", a);
}
#define a i++
void main ( )
{
int i=0;
if (0==a);
#define a --1
else
#define a ++i
printf ("%d", a);
}
- 2
- Garbage
- No output
- Compilation error
93. Find the output
void main ( )
{
int a=0;
switch (a)
{
case 0:
switch (a)
{
case 0: goto default;
break;
case 1: printf ("ho ho");
default : printf ("ha ha");
}
case 1: printf ("he he");
default : printf (" ");
}
}
void main ( )
{
int a=0;
switch (a)
{
case 0:
switch (a)
{
case 0: goto default;
break;
case 1: printf ("ho ho");
default : printf ("ha ha");
}
case 1: printf ("he he");
default : printf (" ");
}
}
- ha ha he he
- ha ha
- No output
- Compilation error
94. Find the output
void main ( )
{
int i;
for (i=1; i<=450; i++)
printf("Hello");
if (i==10)
break;
printf("Hi");
}
void main ( )
{
int i;
for (i=1; i<=450; i++)
printf("Hello");
if (i==10)
break;
printf("Hi");
}
- Hello 10 times
- Hello 10 times and hi
- Hello 450 times and hi once
- Compilation error
95. Find the output
void main ( )
{
int i=98;
while (100-i++)
printf ("%u", i);
switch (i)
case 'e': printf ("Foo1");
}
void main ( )
{
int i=98;
while (100-i++)
printf ("%u", i);
switch (i)
case 'e': printf ("Foo1");
}
- 98 99 100
- 99 100
- 99 100 Foo1
- Compilation error
96. Find the output
#define switch case
#define if switch
void main ( )
{
int i=1;
if (i)
{
switch 1:
{
case 0:
printf ("It's magic");
break;
}
case 2:
printf ("\n No magic");
break;
case 1*2+4:
printf("it's music");
}
}
#define switch case
#define if switch
void main ( )
{
int i=1;
if (i)
{
switch 1:
{
case 0:
printf ("It's magic");
break;
}
case 2:
printf ("\n No magic");
break;
case 1*2+4:
printf("it's music");
}
}
- It's magic
- No magic
- No output
- Compilation error
97. Find the output
void main ( )
{
int i=10, j=15, k=5;
if ((i?j:k)=J%3)
printf ("%d",j);
}
void main ( )
{
int i=10, j=15, k=5;
if ((i?j:k)=J%3)
printf ("%d",j);
}
- 5
- 15
- 3
- Compilation error