What is the right choice, if the following loop is implemented?
void main()
{
int num = 0;
do{
--num;
printf("%d", num);
}while( ++num >= 0 );
}
void main()
{
int num = 0;
do{
--num;
printf("%d", num);
}while( ++num >= 0 );
}
A. A run time error will be generated.
B. The program will not enter into the loop.
C. There will be a compilation error reported.
D. The loop will run infinitely many times.
E. Prints the value of 0 one time only.
Answer: Option D
Solution(By Examveda Team)
As the value of num is decremented(--num) and again incremented(++num) and hence no change in num and it remains 0 only causing infinite loop.
Join The Discussion
Comments ( 1 )
Which control structure is used to repeatedly execute a block of code in C?
A. for loop
B. if statement
C. switch case
D. while loop
In C, what is the purpose of the 'break' statement within a loop?
A. Continue to the next iteration
B. Exit the program
C. Terminate the loop and exit it
D. Skip the current iteration
What is the purpose of the 'else' statement in C's 'if-else' control structure?
A. Execute the 'if' block
B. Execute the 'else' block
C. Execute both 'if' and 'else' blocks
D. Skip the 'if' block
Which control structure is used to make a decision between two or more alternatives in C?
A. switch case
B. for loop
C. if statement
D. while loop
The Out put will be -1 for infinite times