ProgrammingHard
char s[] = "xyz"; for (int i = 0; s[i]; i++) s[i] = (s[i] - 'a' + 3) % 26 + 'a'; printf("%s", s); What is printed?
- A. cde
- B. xyz
- C. abc
- D. bcd
Correct answer: C. abc
Each letter moves 3 places with wrap-around: x becomes a, y becomes b and z becomes c. All intermediate values are non-negative, so % behaves as expected.
More C Programming questions
- char d[8] = "#######"; strncpy(d, "ab", 5); int z = 0; for (int i = 0; i < 8; i++) if (d[i] == 0) z++; printf("%d", z); What is printed?
- int a = 0, b = 0; char op = 0; int n = sscanf("12 + x", "%d %c %d", &a, &op, &b); printf("%d %c", n, op); What is printed?
- Which loop is safe for every value a plain char can hold, including bytes above 127 that may be negative?
- What is the smallest array size that holds the string "Ravi" with strcpy and no undefined behaviour?
- char s[] = "x41x420x43"; printf("%zu", strlen(s)); What is printed?
- char s[] = "banana"; char p = strrchr(s, 'a'); printf("%ld", (long)(p - s)); What is printed?