ISRO CS 2014
September 26, 2023
Programming
September 30, 2023
ISRO CS 2014
September 26, 2023
Programming
September 30, 2023

Programming-for-Output-Problems

Question 6

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 _____.

A
5
B
6
C
7
D
8
Question 6 Explanation: 

We know that arr is a pointer to arr[ ] & hence arr+4 is pointer to 4th index of array (starting from 0 to 4).
Now *ip is a pointer of int type pointing to memory location 108, which is part of arr.
Hence, when we will print ip[1] it will be equivalent to *(ip+1).

Address of ip will be incremented by 1 & value inside 110 will be printed.
Correct Answer: B
Question 6 Explanation: 

We know that arr is a pointer to arr[ ] & hence arr+4 is pointer to 4th index of array (starting from 0 to 4).
Now *ip is a pointer of int type pointing to memory location 108, which is part of arr.
Hence, when we will print ip[1] it will be equivalent to *(ip+1).

Address of ip will be incremented by 1 & value inside 110 will be printed.
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
error: Alert: Content selection is disabled!!