Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

GATE | GATE CS 2010 | Question 10

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

What does the following program print?
 

C




#include
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);
  getchar();
  return 0;
}

(A)

2 2
 

(B)

2 1
 

(C)

0 1
 

(D)

0 2 
 


Answer: (D)

Explanation:

See below comments for explanation. 

 

/* p points to i and q points to j */
void f(int *p, int *q)
{
  p = q;    /* p also points to j now */
 *p = 2;   /* Value of j is changed to 2 now */
}

 


Quiz of this Question
Please comment below if you find anything wrong in the above post

My Personal Notes arrow_drop_up
Last Updated : 28 Jun, 2021
Like Article
Save Article
Similar Reads