ProgrammingHardProduct company OA
Assume ASCII. What does f("Code21") print?
Assume ASCII. What does f("Code21") print?
void f(const char *s) {
if (*s) {
f(s + 1);
if (*s % 2) putchar(*s);
}
}- A. 1eC
- B. 1eoC
- C. Coe1
- D. Ceo1
Correct answer: B. 1eoC
The print happens after the recursive call, so characters come out in reverse. Only odd character codes print: 'C' 67, 'o' 111, 'e' 101 and '1' 49 are odd; 'd' 100 and '2' 50 are even. Reversed: 1, e, o, C.
More C Programming questions
- What is printed? c int a = 1, b = 2, c = 3; int arr[] = {&a, &b, &c}; int pp = arr + 1; pp += 10; pp[1] += 20; printf("%d %d %d", a, b, c);
- Assume 32-bit unsigned int. What is printed? c unsigned mask(int lo, int hi) { return ((1u << (hi - lo + 1)) - 1) << lo; } int main(void)…
- What is printed? c int f(unsigned x) { int c = 0; while (x & (x >> 1)) { x &= x >> 1; c++; } return c + (x != 0); } int main(void) {…
- What is printed? c char d[6] = "zzzzz"; strncpy(d, "abc", 2); printf("%s", d);
- Assume ASCII. What is printed? c char s[] = "xyzAB"; for (char p = s; p; p++) if (p >= 'a' && p <= 'z') p = 'a' + (p - 'a' + 3) % 26…
- What is printed? c int up(int a, int b) { return (a + b - 1) / b; } int main(void) { printf("%d %d %d", up(10, 3), up(9, 3), up(0, 3)); }