What does the following program print?
#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; } |
chevron_right
filter_none
(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 */
}
Recommended Posts:
- GATE | GATE CS 2010 | Question 4
- GATE | GATE CS 2010 | Question 5
- GATE | GATE CS 2010 | Question 6
- GATE | GATE CS 2010 | Question 65
- GATE | GATE CS 2010 | Question 8
- GATE | GATE CS 2010 | Question 65
- GATE | GATE CS 2010 | Question 11
- GATE | GATE CS 2010 | Question 65
- GATE | GATE CS 2010 | Question 13
- GATE | GATE CS 2010 | Question 14
- GATE | GATE CS 2010 | Question 15
- GATE | GATE CS 2010 | Question 16
- GATE | GATE CS 2010 | Question 65
- GATE | GATE CS 2010 | Question 3
- GATE | GATE CS 2010 | Question 37
- GATE | GATE CS 2010 | Question 58
- GATE | GATE CS 2010 | Question 57
- GATE | GATE CS 2010 | Question 56
- GATE | GATE CS 2010 | Question 55
- GATE | GATE CS 2010 | Question 54

