Question 23Asked in DSSSB TGT Computer Science (Technical), 12 Sep 2025, Shift 1 (9:00 AM)

What happens when the following code executes? int main() {

What happens when the following code executes? #include <stdio.h> int main() { char buffer[50]; int n = sprintf(buffer, "Hello, World!"); printf("%d %s", n, buffer); return 0; }
  1. APrints '13 Hello'
  2. BPrints '12 Hello'
  3. CPrints '12 Hello, World!'
  4. DPrints '13 Hello, World!'
Show answerHide answer

Correct answer: (D) Prints '13 Hello, World!'

Explanation

sprintf writes "Hello, World!" into buffer and returns the number of characters written, which is 13 (5 + comma + space + 5 + !). printf then prints "13 Hello, World!".

From DSSSB TGT Computer Science PYQ (Technical), 12 Sep 2025, Shift 1 (9:00 AM)

This is question 23 of DSSSB TGT Computer Science PYQ (Technical), 12 Sep 2025, Shift 1 (9:00 AM). 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.