Question 27Asked in DSSSB TGT Computer Science (Technical), 12 Sep 2025, Shift 3 (5:00 PM)

What will be the output of the following code when the input is HelloWorld?

What will be the output of the following code when the input is HelloWorld? #include <stdio.h> int main() { char str[5]; // Buffer for input int result = scanf("%4s", str); if (result == 1) { printf("Input: %s\n", str); } else { printf("Input error or no input.\n"); } return 0; }
  1. AInput: Hell
  2. BInput: Hello
  3. CInput error or no input
  4. DInput: HelloWorld
Show answerHide answer

Correct answer: (A) Input: Hell

Explanation

The width %4s makes scanf read at most 4 characters, so str gets "Hell" plus '\0' (fits in 5 bytes). scanf returns 1, so "Input: Hell" is printed.

From DSSSB TGT Computer Science PYQ (Technical), 12 Sep 2025, Shift 3 (5:00 PM)

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