ProgrammingModerate
char s[] = "12345"; int v = 0; for (int i = 0; s[i]; i++) v = v * 10 + (s[i] - '0'); printf("%d", v); What is printed?
- A. 54321
- B. 15
- C. 12345
- D. 1234
Correct answer: C. 12345
Each character adds one more digit at the right, so the loop rebuilds the number 12345.
More C Programming questions
- char s[] = "ab"; char q = s + 2; printf("%d", q); What is printed?
- char c = 'A'; printf("%d %c", c + 1, c + 1); What is printed?
- printf("%s", "abc" + 1); What is printed?
- char name[] = "Bob"; char p = name; printf("%c%c", p[0], (p + 2)); What is printed?
- char buf[] = "ab"; buf[2] = 'c'; printf("%zu", sizeof buf); What is printed?
- char s[3] = "ab"; printf("%zu", sizeof s); What is printed?