Loops
- In the program given below, point out the error, if any, in the while loop.
#include <studio.h>
int main()
{
int k = 5;
while ( )
{
printf("%d\n", k++);
if (k >10)
break;
}
return 0;
}
-
View Hint View Answer Discuss in Forum
The while() loop must have a conditional expression or it shows "Expression syntax" error.
Correct Option: A
The while() loop must have a conditional expression or it shows "Expression syntax" error.
- Which keyword is used to exit a loop?
-
View Hint View Answer Discuss in Forum
exit will terminate the program execution, goto is used to jump to another statement, continue is used to skip the immediate statement and start from the beginning.
Correct Option: C
break keyword is used to break from the loop.
exit will terminate the program execution, goto is used to jump to another statement, continue is used to skip the immediate statement and start from the beginning.
- What will be the output of the following C code?
#include <stdio.h>
int main()
{
int k = 0, L = 0;
while (k < 3)
{
Level1 : k++;
while (L < 4)
{
printf("Interview Mania");
goto Level1;
}
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
"Interview Mania" is printed infinite times
- What will be the output of the following C code?
#include <stdio.h>
int main()
{
printf("Interview");
goto Level1;
printf("Mania");
}
void fun()
{
Level1 : printf("Hello");
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Compilation Error
main.c: In function ‘main’:
main.c:5:9: error: label ‘Level1’ used but not defined
goto Level1;
- What will be the output of the following C code?
#include <stdio.h>
int main()
{
printf("Welcome ");
Level1:Level2:
printf("To ");
printf("Interview Maina");
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
Welcome To Interview Maina