Open In App

GATE | GATE CS 2019 | Question 33

Last Updated : 05 Aug, 2021
Like Article
Like
Save
Share
Report

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) 6
(B) 5
(C) 4
(D) segmentation error


Answer: (A)

Explanation:




#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;
}


Note that index of array always start from 0 in C.

Initially ip pointer is pointing at (arr+4) or skipping starting first 4 position.

Now in the printf system call, 1 more position is to skip, So it will point to (arr+5) or skip 5 position from starting:

Hence, printf will print value at 6th position, i.e., 6 will printed.

So, option (A) is correct.



Quiz of this Question


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads