C-Loop Question and Answer
C-Loop Question and Answer
1. Which of the following is true about "for" loop?
- Any of the three experssions may be omitted
- The openng and closing parentheses and the semicoons must be included.
- The initial expression is evaluated only once.
- All the above
2. Find the output
void main ( )
{
int x=10, y;
for (y=10; y!=x;++y)
printf ("%d", y);
printf("%d", y);
}
void main ( )
{
int x=10, y;
for (y=10; y!=x;++y)
printf ("%d", y);
printf("%d", y);
}
- 10 11
- 10
- 11
- None of these
3. If a loop loses its start value that loop is called as
- Odd loop
- Unknown loop
- At least once
- Infinite loop
4. Find the output
void main ( )
{
int i=1;
do {
printf("%d", i);
i++;
}
while (!i==5);
}
void main ( )
{
int i=1;
do {
printf("%d", i);
i++;
}
while (!i==5);
}
- 1 2 3 4 5
- 1 2 3 4 5 6
- 1
- None of these
5. Find the output
void main ( )
{
int i;
for (i=0; i<3; i++);
printf("%d", i*i);
printf ("strange");
}
void main ( )
{
int i;
for (i=0; i<3; i++);
printf("%d", i*i);
printf ("strange");
}
- 9strange
- 014strange
- strange
- Compilation error
6. Find the output
void main ( )
{
int i;
for (i=0; i<3; i++);
printf("%d", i*i);
printf ("strange");
}
void main ( )
{
int i;
for (i=0; i<3; i++);
printf("%d", i*i);
printf ("strange");
}
- 9strange
- 014strange
- strange
- Compilation error
7. Find the output
void main ( )
{
int i, j=1;
for (i=1; i<5; i++)
while (j<5)
{
printf ("%d', i+j);
if(i==2&& j==2)
break;
j++;
}
}
void main ( )
{
int i, j=1;
for (i=1; i<5; i++)
while (j<5)
{
printf ("%d', i+j);
if(i==2&& j==2)
break;
j++;
}
}
- 23454556
- 2345
- Compilation error
- None of these
8. Find the output
void main ( )
{
int i=1;
while (!i=5)
{
printf ("%d", i);
i++;
}
}
void main ( )
{
int i=1;
while (!i=5)
{
printf ("%d", i);
i++;
}
}
- 1
- 12345
- 1234
- Compilation error
9. Find the output
void main ( )
{
for (putchar ('g'), i); putchar ('o'putchar ('d'))
putchar ('s');
}
void main ( )
{
for (putchar ('g'), i); putchar ('o'putchar ('d'))
putchar ('s');
}
- godsgodsgods...
- gosdgosdgosd...
- gosdosdosdosd...
- Compilation error
10. Find the output
void main ( )
{
char m[ ]={"hello world"}'
int n;
for (c=sizeof(m); m; putch(m)[-n]));
}
void main ( )
{
char m[ ]={"hello world"}'
int n;
for (c=sizeof(m); m; putch(m)[-n]));
}
- d1row olleh
- hello world
- dddddddddd.....
- infinite loop