C-Control Structure Question and Answer
C-Control Structure Question and Answer
51. Find the output
void main ( )
{
int x=100, y=200, z=300, i=300;
if (i==z)
i=x;
else
y=y+z;
if (i!=z)
z=z+x;
else
y=y+z;
printf("5d", y);
}
void main ( )
{
int x=100, y=200, z=300, i=300;
if (i==z)
i=x;
else
y=y+z;
if (i!=z)
z=z+x;
else
y=y+z;
printf("5d", y);
}
- 100
- 200
- 300
- 500
52. Find the output
int i=4;
void main ( )
{
switch (i)
{
default:
;
case 3:
i +=5;
if (i==8);
{
i++;
if (i=9);
i*=2;
}
i -=4;
break;
case 8:
i +=5;
break;
}
printf("%d\n", i);
}
int i=4;
void main ( )
{
switch (i)
{
default:
;
case 3:
i +=5;
if (i==8);
{
i++;
if (i=9);
i*=2;
}
i -=4;
break;
case 8:
i +=5;
break;
}
printf("%d\n", i);
}
- 5
- 16
- 18
- 14
53. Find the output
void main ( )
{
int a=0, b=20;
char x=1, y=10;
if (x, b--, x--, x++)
printf("%d", x);
}
void main ( )
{
int a=0, b=20;
char x=1, y=10;
if (x, b--, x--, x++)
printf("%d", x);
}
- 0
- 1
- 2
- None of the above
54. Find the output
void main ( )
{
int x=1, y=1, z;
if (y<0) if (y>0) x3;
else x=5;
printf("%d", x);
}
void main ( )
{
int x=1, y=1, z;
if (y<0) if (y>0) x3;
else x=5;
printf("%d", x);
}
- 5
- 3
- 1
- Compilation error
55. Find the output
int main ( )
{
unsigned val =0Xabcd;
if (vval>>16|val<<16)
{
printf("Success");
}
return;
printf("Failure");
}
int main ( )
{
unsigned val =0Xabcd;
if (vval>>16|val<<16)
{
printf("Success");
}
return;
printf("Failure");
}
- No output
- Success
- Failure
- SuccessFailure
56. Find the output
void main ( )
{
int a=1;
if (a)
printf ("Test");
else;
printf("Again");
}
void main ( )
{
int a=1;
if (a)
printf ("Test");
else;
printf("Again");
}
- Again
- Test
- Compilation error
- TestAgain
57. Find the output
void main ( )
{
static int choice;
switch (-- choice, choice -1,
choice -1, choice+=2)
{
case 1:
printf("Choice1");
break;
case 2:
printf("Choice2");
break;
default ;
printf("Default");
}
}
void main ( )
{
static int choice;
switch (-- choice, choice -1,
choice -1, choice+=2)
{
case 1:
printf("Choice1");
break;
case 2:
printf("Choice2");
break;
default ;
printf("Default");
}
}
- Choice1
- Choice2
- Default
- None of these
58. Find the output
void main ( )
{
char ch='r';
if (ch=='a'||ch='h')
ch='u';
printf("%c", ch);
}
void main ( )
{
char ch='r';
if (ch=='a'||ch='h')
ch='u';
printf("%c", ch);
}
- r
- a
- u
- Compilation error
59. Find the output
#define FALSE -1
#define TRUE 1
#define NULL 0
void main ( )
{
if (NULL)
puts ("NULL");
else if(FALSE)
puts ("TRUE");
else { };;
puts ("FALSE");
}
#define FALSE -1
#define TRUE 1
#define NULL 0
void main ( )
{
if (NULL)
puts ("NULL");
else if(FALSE)
puts ("TRUE");
else { };;
puts ("FALSE");
}
- TRUE TRUE
- TRUE FALSE
- FALSE FALSE
- FALSE TRUE
60. Find the output
void some_method(int);
int i=1;
void main ( )
{
some_method (i);
}
some_method(i)
{
if (i)
{
printf {If");
some_method (0);
}
else
{
printf ("Else");
}
}
void some_method(int);
int i=1;
void main ( )
{
some_method (i);
}
some_method(i)
{
if (i)
{
printf {If");
some_method (0);
}
else
{
printf ("Else");
}
}
- IfElse
- E1self
- If
- Compilation error