C | Loops & Control Structure | Question 9

Output?

filter_none

edit
close

play_arrow

link
brightness_4
code

#include <stdio.h>
int main()
{
    int c = 5, no = 10;
    do {
        no /= c;
    } while(c--);
   
    printf ("%d\n", no);
    return 0;
}

chevron_right


(A) 1
(B) Runtime Error
(C) 0
(D) Compiler Error


Answer: (B)

Explanation: There is a bug in the above program. It goes inside the do-while loop for c = 0 also. So it fails during runtime.



My Personal Notes arrow_drop_up