For gdb debugger

(gdb) p &buffer

This command is used to print the content of starting of buffer (stack), or print the address?

If it is content, how to print the address?


It depends on what type the buffer is.

Most likely buffer is a pointer to the start of the buffer. The C-style declaration for it might be struct stackElement *buffer; or something similar (note the asterisk!). In that case:

  • p &buffer prints the address where the pointer itself is stored (i.e. "the address of the address of the buffer")
  • p buffer should print the value of the buffer pointer variable, which is the address of the buffer.
  • p *buffer should print the contents of the buffer.

If bufferis some structure type, and not a pointer (example C declaration might be struct stackElement buffer; with no asterisk), then:

  • p &buffer prints the address where the structure is, i.e. the address of the buffer
  • p buffer prints the contents of this structure (= if this is a stack, probably the first stack element)
  • p *buffer is an error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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