Most Tricky GATE Questions on Pointers

Last updated on

Are you a GATE aspirant?

And, want a step by step solution✍ on pointers?

Here, I came up with the most tricky GATE questions on pointers.

From the previous years’ questions, I picked up the four most tricky ones with step-by-step clarification to get a solid grip on pointers.

Let’s start it.

Question 1: (GATE 2011: 1 Marks)

What does the following fragment of C program print?

char c[]="GATE2011';
char *p=c;
printf("%s",p+p[3]-p[1]);
  1. GATE2011
  2. E2011
  3. 2011
  4. 011
Gate Pointer Question 1

Question 2: (GATE 2008: 2 Marks)

What is printed by the following C program?

int f(int x, int *py, int **ppz)
{ int y,z;
**ppz+=1; z=**ppz;
*py+=2; y=*py;
x+=3;
return x+y+z;}
void main()
{ int c, *b, **a;
c=4; b=&c; a=&b;
printf("%d",f(c,b,a));
}
  1. 18
  2. 19
  3. 21
  4. 22

Question 3: (GATE 2017: 1 Marks)

Consider the following function implemented in C:

void printxy(int x, int y)
{
int *ptr;
x=0;
ptr=&x;
y=*ptr;
*ptr=1;
printf("%d",%d",x,y);
}

The output of invoking printxy(1,1) is

  1. 0, 0
  2. 0, 1
  3. 1, 0
  4. 1, 1
Gate Pointer Question 3

Question 4: (GATE-2018)

What does the following program print?

#include<stdio.h>
void f(int *p, int*q)
{
p=q;
*p=2;
}
int i=0, j=1;
int main()
{
f(&i, &j);
printf("%d%d\n",i,j);
return 0;
}
  1. 2 2
  2. 2 1
  3. 0 1
  4. 0 2
Gate Pointer Question 4

Final Words

If you’re a CS GATE aspirant, it’s very important to have a clear concept on pointers and array.

Sometimes, it becomes very difficult to find a step-by-step solution to a program. So, I tried to help you to solve the GATE questions on pointers.

Hope, you liked this post, and have you any related suggestions or query, feel free to let me know.👇


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *