Question 143Asked in DSSSB TGT Computer Science, 25 Jun 2023, Shift 2 (12:30 PM)

What will the output of the given program be? main()

What will the output of the given program be? #include<stdio.h> main() { printf(6+"Hello World\n"); }
  1. A6He110 world
  2. BCompilation error
  3. CWorld
  4. DHello
Show answerHide answer

Correct answer: (B) Compilation error

Explanation

Note: the answer key gives (B), but the code compiles. 6 + "Hello World\n" is pointer arithmetic that skips the first 6 characters, so printf prints 'World' (C).

From DSSSB TGT Computer Science PYQ, 25 Jun 2023, Shift 2 (12:30 PM)

This is question 143 of DSSSB TGT Computer Science PYQ, 25 Jun 2023, Shift 2 (12:30 PM). See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.