C-Loop Question and Answer
C-Loop Question and Answer
61. Find the outputt
void main (int seizeofargv, char *argv[ ])
{
while (sizeofargv)
printf ('%s', argv[-- sizeof argv]);
}
void main (int seizeofargv, char *argv[ ])
{
while (sizeofargv)
printf ('%s', argv[-- sizeof argv]);
}
- Garbage string
- filename.exe
- filename.c
- filename.obj
62. Find the output
void main ( )
{
int x, y=1, z;
if (x=z=y); x=3;
while (y<4) x+=++y;
printf('%d %d\n", x, y);
}
void main ( )
{
int x, y=1, z;
if (x=z=y); x=3;
while (y<4) x+=++y;
printf('%d %d\n", x, y);
}
- 3 1
- 12 4
- 12 5
- 3 5
63. Find the output
int i;
void main ( )
{
int j;
for (j=2; printf("%d', i)-j; printf("%d", j))
printf("%d", j--);
}
int i;
void main ( )
{
int j;
for (j=2; printf("%d', i)-j; printf("%d", j))
printf("%d", j--);
}
- 0210100
- 0210
- 021010
- Compilation error
64. Find the output
void main ( )
{
char as [ ] ="\\00\0";
int i=0;
do
{
switch(as[i++])
{
case '\\'; : printf("A");
break;
case 0: printf("B");
break;
default: printf ("C");
break;
}
}
while (i<3);
}
void main ( )
{
char as [ ] ="\\00\0";
int i=0;
do
{
switch(as[i++])
{
case '\\'; : printf("A");
break;
case 0: printf("B");
break;
default: printf ("C");
break;
}
}
while (i<3);
}
- ABC
- ACB
- CAB
- CBA
65. Find the output
void main ( )
{
int a=5;
for (;a=0 ? !a:a;)
printf("Hello");
}
void main ( )
{
int a=5;
for (;a=0 ? !a:a;)
printf("Hello");
}
- Infinite loop
- Compilation error
- Hello will be printed only once
- No output
66. Find the output
void main ( )
{
char str [ ]="ANDAMAN NIKOBAR";
int i, c, A=0, N=0, Extra=0;
for (i=0; (c=str [i])! = c; i++)
{
switch (c)
{
case 'A' : A++;
continue;
case 'N" : N++;
default : EXTRA++;
}
}
printf("%d", EXTRA);
}
void main ( )
{
char str [ ]="ANDAMAN NIKOBAR";
int i, c, A=0, N=0, Extra=0;
for (i=0; (c=str [i])! = c; i++)
{
switch (c)
{
case 'A' : A++;
continue;
case 'N" : N++;
default : EXTRA++;
}
}
printf("%d", EXTRA);
}
- 10
- 11
- 12
- 13
67. Find the output
void main ( )
{
int p=3;
while (p--);
{
static int i=3;
printf("%d", --i);
}
}
void main ( )
{
int p=3;
while (p--);
{
static int i=3;
printf("%d", --i);
}
}
- 2 1 0
- 2 2 2
- Infinite loop
- 2
68. Find the o utput
void main ( )
{
int x=0;
for (;;)
{
if (x++==4) break;
continue;
}
printf("x = %d", x);
}
void main ( )
{
int x=0;
for (;;)
{
if (x++==4) break;
continue;
}
printf("x = %d", x);
}
- x=0
- x=4
- x=5
- Infinite loop
69. Find the output
void main ( )
{
int i,j;
i=1;
j=5;
for (;++i<--j;)
continue;
printf('5d %d", i, j);
}
void main ( )
{
int i,j;
i=1;
j=5;
for (;++i<--j;)
continue;
printf('5d %d", i, j);
}
- 3 4
- 2 4
- 3 2
- 3 3
70. Find the output
void main ( )
{
int i=0;
for (-i--; ++i; printf('%d", i));
printf("%d", i);
}
void main ( )
{
int i=0;
for (-i--; ++i; printf('%d", i));
printf("%d", i);
}
- 0
- Infinite loop
- 1
- Compilation error