Skip to content
GATEiit

GATE CSE 2019 Q34: Pointer ip = arr + 4: value of ip[1]

Syllabus topic: Programming in C

Question

Consider the following C program:

#include <stdio.h>
int main(){
    int arr[]={1,2,3,4,5,6,7,8,9,0,1,2,5}, *ip=arr+4;
    printf("%d\n", ip[1]);
    return 0;
}

The number that will be displayed on execution of the program is_________ .

Try it: numerical answer: type the value

Numerical answer. No negative marking.
Show answer and explanation

Answer: 6 (official GATE 2019 final answer key)

Concept used: Pointer arithmetic: ip[1] means *(ip + 1), so with ip = arr + 4 it is arr[5].

Concept notes

Loading notes…

First step: Rewrite ip[1] as an index into arr and read that element (indices start at 0).

Full step-by-step solution

Loading…

Answer from the official final answer key. Found a mistake? Use Report issue and we will fix it.

More questions on Programming in C

Every PYQ on this topic →

Share this question

WhatsAppDownload image

Source: official GATE 2019 CS question paper and final answer key, organised by IIT Madras. Question paper · Answer key