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]);
- GATE2011
- E2011
- 011
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));
}
- 18
- 21
- 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
- 0, 0
- 0, 1
- 1, 1
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;
}
- 2 2
- 2 1
- 0 1
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.👇
Leave a Reply