Machine-translated by Google. Questions are authored in English.
Top

Discussion

Output?

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

 

  • A.1
  • B.Runtime Error
  • C.Compiler Error

Answer: B

Correct answer: Runtime Error

The loop divides no by c and then tests c--, so c falls 5, 4, 3, 2, 1, 0. On the pass after the test that saw c equal to 1, c is 0 - and no /= 0 is integer division by zero, which the hardware traps. The compiler cannot see it, so it is a run-time fault.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.