2

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.

3
  • 1
    *p and *pp don't make sense. They are de-referencing p and pp, but those are not pointers. Do you mean &p and &pp? Jan 27, 2015 at 21:24
  • Spend more time reading books (or web pages) about address space, virtual memory, process, C programming, pointer. Compile your program with all warnings & debug info (gcc -Wall -Wextra -g) then use a debugger (gdb) to run your program step by step and display some data (e.g. pointer variable, and dereference them) Jan 27, 2015 at 21:26
  • * works in the exactly opposite way from what you have guessed. Jan 27, 2015 at 21:27

3 Answers 3

4

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
1

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
0

Here's how everything works out:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.