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

What will be the output of the C program given below? int* func()

What will be the output of the C program given below? #include <stdio.h> int* func() { static int arr[5] = { 1, 2, 3, 4, 5 }; return arr; } int main() { int* ptr = func(); printf("Array Elements: "); for (int i = 0; i < 5; i++) { printf("%d ", *ptr); } return 0; }
  1. A1 1 3 4 1
  2. B2 3 4 5 0
  3. C1 2 3 4 5
  4. D1 1 1 1 1
Show answerHide answer

Correct answer: (D) 1 1 1 1 1

Explanation

ptr is never incremented inside the loop, so *ptr always reads arr[0] = 1, printing 1 five times (after "Array Elements: "). To print 1 2 3 4 5 the loop would need ptr[i] or *(ptr + i).

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

This is question 43 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.