Consider the following code segment:

int arr[ ] = {0, 1, 2, 3, 4};

int i=1, *ptr;

ptr=arr + 2;

arrange the following printf statements in the increasing order of their output.

(A) printf("%d", ptr[i]);

(B) printf ("%d", ptr[i+1]);

(C) printf ("%d", ptr[-i]);

(D) printf ("%d", ptr[-i+1]);

Choose the correct answer from the options given below :

This question was previously asked in
UGC NET Computer Science (Paper 2) 07 Dec 2023 Official Paper
View all UGC NET Papers >
  1. (C), (A), (B), (D)
  2. (C), (D), (A), (B)
  3. (D), (A), (B), (C)
  4. (A), (B), (D), (C)

Answer (Detailed Solution Below)

Option 2 : (C), (D), (A), (B)
Free
UGC NET Paper 1: Held on 21st August 2024 Shift 1
8.7 K Users
50 Questions 100 Marks 60 Mins

Detailed Solution

Download Solution PDF

The correct answer is (C), (D), (A), (B)

EXPLANATION:

  • (A) printf("%d", ptr[i]);
    • This will print the value of the 'i' index from the 'ptr', which is the array starting from the index '2'. So ptr[i] is equivalent to arr[2+i], which is arr[3] = 3.
  • (B) printf ("%d", ptr[i+1]);
    • This will print the value of the 'i+1' index from the 'ptr'. ptr[i+1] is equivalent to arr[2+i+1], which is arr[4] = 4.
  • (C) printf ("%d", ptr[-i]);
    • This accesses the element at the position '-i' from the starting point of 'ptr'. ptr[-i] is equivalent to arr[2-i] which is arr[1] = 1.
  • (D) printf ("%d", ptr[-i+1]);
    • This accesses the element at the position '-i+1' from 'ptr'. ptr[-i+1] is equivalent to arr[2-i+1] which is arr[2] = 2.

So the increasing order of their output is (C) < (D) < (A) < (B).

This corresponds to choice 2) (C), (D), (A), (B).

Latest UGC NET Updates

Last updated on Jun 6, 2025

-> The UGC NET Exam Schedule 2025 for June has been released on its official website.

-> The UGC NET Application Correction Window 2025 is available from 14th May to 15th May 2025.

-> The UGC NET 2025 online application form submission closed on 12th May 2025.

-> The June 2025 Exam will be conducted from 21st June to 30th June 2025

-> The UGC-NET exam takes place for 85 subjects, to determine the eligibility for 'Junior Research Fellowship’ and ‘Assistant Professor’ posts, as well as for PhD. admissions.

-> The exam is conducted bi-annually - in June and December cycles.

-> The exam comprises two papers - Paper I and Paper II. Paper I consists of 50 questions and Paper II consists of 100 questions. 

-> The candidates who are preparing for the exam can check the UGC NET Previous Year Papers and UGC NET Test Series to boost their preparations.

Get Free Access Now
Hot Links: teen patti game online teen patti yas teen patti real cash game teen patti casino download teen patti gold download apk