ProgrammingModerate
char c = 'a' + 25; printf("%c", c); What is printed on an ASCII system?
- A. y
- B. z
- C. a
- D. {
Correct answer: B. z
In ASCII the lowercase letters are consecutive from 'a' = 97, so 'a' + 25 = 122 is 'z', the 26th letter. 'y' is the off-by-one from counting 'a' as +1, and '{' is 'a' + 26. The C standard guarantees consecutive codes only for digits, hence the ASCII assumption.
More C Programming questions
- int r = strcmp("abc", "abd"); What can be said about r according to the C standard?
- const char s = "abcabc"; printf("%ld", (long)(strstr(s, "ca") - s)); What is printed?
- char d[4] = "abc"; printf("%zu", sizeof d - strlen(d)); What is printed?
- char s[] = "Hello"; for (char p = s; p; p++) if (p >= 'a' && p <= 'z') p -= 32; printf("%s", s); What is printed?
- int a, b; int n = sscanf("12-34", "%d-%d", &a, &b); printf("%d", b); What is printed?
- char s[10], w[10]; int n = 0; sscanf("abc123", "%[a-z]%d", s, &n); printf("%d", n); What is printed?