ProgrammingModerateTCS NQT · Wipro
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
unsigned char c = 254;
int n = 0;
while (++c)
n++;
printf("%d", n);
}- A. 2
- B. 1
- C. 0
- D. 255
Correct answer: B. 1
c goes from 254 to 255, which makes the loop body run once, and the next increment wraps c to 0, so the loop stops. The count is 1.
More C Programming questions
- How many iterations does this binary search make to find 13 in the sorted array 0 to 15? Compute with the program. c #include <stdio.h>…
- n <= 10^5 values, each up to 10^9, must be summed. Which declaration is correct for the total?
- To test whether n = 10^12 is prime by trial division up to sqrt(n), which loop is correct?
- A middle index of a range [lo, hi] is needed for hi near INTMAX. Which expression is safe?
- A scanf loop reads integers until the end of input. Which loop is correct when the input may end with a non-numeric token?
- A character loop reads bytes with char c = getchar() and tests while (c != EOF). Why can this loop be wrong?