Question discussion

What is the output of the following C program?#include int main() { int n = printf("Hi"); printf("%d", printf("%d", n) + n); return 0; }

1768Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following C program?

#include <stdio.h>
int main() {
    int n = printf("Hi");
    printf("%d", printf("%d", n) + n);
    return 0;
}
  • AHi23
  • BHi32
  • CHi2
  • DHi13
Correct answer: A

Explanation

printf("Hi") returns 2 so n = 2; the inner printf prints 2 and returns 1, and the outer printf prints 1 + 2 = 3, giving Hi23.

Discussion 0

Nobody has replied yet. Start the discussion!