ProgrammingModerateTCS NQT · Wipro

What is printed?

What is printed?
#include <stdio.h>
void rev(const char *s) {
    if (*s == '\0') return;
    rev(s + 1);
    putchar(*s);
}
int main(void) {
    rev("stack");
}
  1. A. stack
  2. B. kcast
  3. C. kcats
  4. D. ktsca

Correct answer: C. kcats

The recursion prints the rest of the string before the current character, so each character appears in reverse order. The output is kcats.

More C Programming questions

Exams that ask this topic