-3

I was just playing with pointer. And I understood only line 5, 6 and 10, 11 completely. What I want to know is which one is the address of pointer here? And what does line 7 and 14 implies? Additionally what is the meaning of %p, using this code as reference.

output is aligned with line

enter image description here

Tony Tannous
  • 14,154
  • 10
  • 50
  • 86
  • 5
    Please do not post code [or output text] as an image or a link to an image. Please _edit_ your question and post the source code as text in a code block. Post your program output [again, as text] in a separate code block. – Craig Estey Sep 16 '20 at 22:51
  • Lines 6, 8, 10 and 13 print the address of the variable `x`, either in base 10 or base 16. Line 12 and 15 print the address of the pointer variable `p` holding the address of x - in base 10 or base 16, respectively. Lines 7 and 14 print an integer value as if it were an address. – Andy Thomas Sep 16 '20 at 23:13
  • The `printf` [format string syntax](https://en.cppreference.com/w/c/io/fprintf#Parameters) indicates that `%p` expects a `void*` argument, so lines 7 and 14 invoke undefined behavior by using `%p` with an argument which is not a pointer. So do lines 6 and 10 by using `%d` with an argument that is not an integer. – dxiv Sep 16 '20 at 23:14

1 Answers1

0

firstly line 7: is a error because you try to print a pointer value but you pass to him a int value 'i' that well print a addressee memory correspond to that int in hex(base 16). For the line 14 : (*p) it's the same thing you pass a int type to pointer because *p return the value who is stocked in the pointer that why it's well print again the address in hex to more understand change the value of i to 15 or higher it well give you his value on hex . The address of pointer it's (&p) because &: mean adress so & of pointer it's the last one line 15 .

benlyazid
  • 92
  • 1
  • 8