Addressing and Dereferencing

Author Topic: Addressing and Dereferencing  (Read 437 times)

Offline beingchinmayTopic starter

  • Trade Count: (0)
  • Jr. Member
  • **
  • Thank You 0
  • Posts: 56
  • Karma: 0
  • Gender: Male
  • I am Chinmay
    • Fat Cutter
Addressing and Dereferencing
« on: 09-03-2016, 03:44:48 »
As in C, the dereferencing, or indirection, operator * is unary and has the same precedence and right-to-left associativity as the other unary operators. If p is a pointer, *p is the value of the variable that p points to. The direct value of p is a memory location, whereas *p is the indirect value of p—namely, the value at the memory location stored in p. In a certain sense, * is the inverse operator to &. Here is code showing some of
these relationships:


Quote
int i = 5, j;
int* p = &i; // pointer p is init to address of i
cout << *p << " = i stored at " << p << endl;
j = p; // illegal pointer not convert to int
j = *p + 1; // legal
p = &j; // p points to j


 

Related Topics

  Subject / Started by Replies Last post
0 Replies
845 Views
Last post 12-19-2015, 02:58:15
by chinmay.sahoo