Mike
Mike

Reputation: 21

Pointer to a Pointer in C?

Chart I have to use to find the value of a, p, pp, *p, *pp, and **pp:

Variable    Address    Value

            36          4
 a          40          1
            44          2
            48         44
 p          52         40
            56         36
            60         44
pp          64         52
            68         56

I arrive at:

a = 1
p = 40
pp = 52

*p = 52
*pp = 64

Is **pp as simple as taking the value located at *pp (52)?? This is really my only idea, otherwise I am confused as to what to do.

Upvotes: 2

Views: 83

Answers (3)

John Bode
John Bode

Reputation: 123578

Here's how everything works out:

 &pp             = 64
  pp = &p        = 52
 *pp =  p  = &a  = 40
**pp = *p  =  a  =  1

Upvotes: 0

R Sahu
R Sahu

Reputation: 206717

Given your chart and variables,

*pp = *(52) = *(&p) = p = 40

Looked at another way,

 pp = &p

And

*p = *(40) = *(&a) = a = 1

which means

p = &a

Upvotes: 1

horns
horns

Reputation: 1933

You have & (address of) and * (dereference) confused.

  • & operator gives you the address of the operand
  • * operator gives you the value at the address pointed to by the operand

Upvotes: 4

Related Questions