Loops
- In the program given below, point out the error, if any, in the for loop.
#include <studio.h>
int main()
{
int i = 1;
for (;;)
{
printf("%d\n", i++);
if (i > 10)
break;
}
return 0;
}
-
View Hint View Answer Discuss in Forum
No error
Correct Option: D
No error
- Which of the following is the correct output for the program given below ?
#include <studio.h>
int main()
{
char i = 0;
for (i<=5 && i>= -1; ++i; i>0)
printf ("%d\n",i);
printf ("%\n");
return 0;
}
-
View Hint View Answer Discuss in Forum
1 2 3 ..... 126 127 -
Correct Option: A
1 2 3 ..... 126 127 -128 - 127 .... -2 -1
- Which of the following statement is correct about the program given below?
#include <studio.h>
int main ()
{
int i = 0;
for(i = 0; i <= 127; printf ("%d", i++))
;
printf ("\n");
return 0;
}
-
View Hint View Answer Discuss in Forum
The program would output 0 1 2 ..... 126 127.
Correct Option: B
The program would output 0 1 2 ..... 126 127.
- Which of the following is the correct output for the program given below?
#include <studio.h>
int main ( )
{
char j = 1;
while (j <= 255)
{
printf("%d",j );
j = j + 1;
}
printf ( "\n");
return 0;
}
-
View Hint View Answer Discuss in Forum
1 2 3 .. 127 -128 -127 -126 .. -2 -1 0 1 2 .. 127 -128 -127 .. infinite times
Correct Option: E
1 2 3 .. 127 -128 -127 -126 .. -2 -1 0 1 2 .. 127 -128 -127 .. infinite times
- Which of the following is the correct output for the program given below?
#include <stdio.h>
int main ( )
{
int k = 5;
while(k-->=0) printf("%d",k);
i = 5;
printf ("\n");
while(k-->=0) printf("%d",k);
printf ("\n");
while(k-->=0) printf("%d",k);
printf("\n");
return 0;
}
-
View Hint View Answer Discuss in Forum
Only first and 2nd loop will be executing here
Correct Option: A
Only first and 2nd loop will be executing here
So output will be.
4 3 2 1 0 -1
4 3 2 1 0 -1