Related Articles

Related Articles

C | Pointer Basics | Question 11
  • Difficulty Level : Easy
  • Last Updated : 05 Feb, 2013
filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


(A) 2 2
(B) 2 1
(C) 0 1
(D) 0 2


Answer: (D)

Explanation: See below f() with 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 */
}

Attention reader! Don’t stop learning now. Get hold of all the important C++ Foundation and STL concepts with the C++ Foundation and STL courses at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :