The Gateway to Computer Science Excellence
+4 votes

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 _______

in Programming by Veteran (431k points)
edited by | 2.7k views

arr is base address of element $1$. 

arr+$4$ is base address of element $5$. Let it ip.

ip[$1$]=*(ip+$1$)= Base address of element $6$. 

6 is the answer. 

6 Answers

+11 votes
Best answer
ip is an integer pointer and the initial assignment sets it to the element at array index $4$ i.e. $5$.(holds address of ar index $4$)
The next statement refers to the next integer after it which is $6 (ip[1]=*(ip+1))$.
by Active (1.2k points)
edited by
+8 votes

Hence Ans is 6.

by Boss (23.9k points)
+3 votes
arr+0 points to the 1st element of the array(index 0) which is 1.

Hence arr+4 will point to the 5th element of the array(index 4) which is 5.

As per assignment $*ip=arr+4$ , $ip[0]=5$

Hence $ip[1]=6$
by Loyal (7.4k points)
+3 votes
int arr[]={1,2,3,4,5,6,7,8,9,0,1,2,5} , *ip = arr+4;


ip is an integer pointer that is currently holding the address where 5 is stored.(i.e. a[4])

ip[1] = *(ip+1) = value present at the next address i.e. 6. so it will print 6.

by Boss (24.1k points)
+1 vote
The program asks for what is the out put of printing ip[1] ,for that we need to understand what ip[1] represents here .it represents the second element of ip[ ] .What ip[ ] represents ? it represents arr[4] so what ip[1] will represent it will be arr[4+1] which is 6 .
by (385 points)
+1 vote
After executing the line---- *ip=arr+4

ip will point to the element 5.

so ip[0]=5


ip[2]=7 ......

by (289 points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,333 answers
105,199 users