ProgrammingHard
char s[] = "abcd"; int n = strlen(s); for (int i = 0; i < n / 2; i++) { char t = s[i]; s[i] = s[n - 1 - i]; s[n - 1 - i] = t; } printf("%c", s[0]); What is printed?
- A. a
- B. b
- C. c
- D. d
Correct answer: D. d
The reversal puts the last letter first, so s[0] becomes 'd'.
More C Programming questions
- char s[] = "a1B2-c"; int n = 0; for (char p = s; p; p++) if (isalpha((unsigned char)p)) n++; printf("%d", n); What is printed?
- char c = 'a' + 1; printf("%c", c); What is printed?
- printf("%5.3s|", "abcdef"); What is printed?
- printf("%d", 7 & ~2); What is printed?
- printf("%d", (1 << 4) | (1 << 2)); What is printed?
- printf("%d", 0x80 >> 7); What is printed?