[Solved] In the following code, I’m confused as to what their values are. Could I get some help here, please? [closed]


In the first case where you print *ptr1, you are printing the value of the variable ptr1 is pointing to (which in this case would be ptr2, which stores the address of var).

In the second case where you print ptr1, you are printing the value of ptr1 (which in this case is the address of ptr2).

In the last case where you print %ptr1, you are printing the address of ptr1.

As @Raman said in the comments: ‘The & operator takes out the address and * operator dereferences the pointer (takes out the value from the address stored as a value) ‘. Remember this if you want to work with pointers.

Side note: If I’m not mistaken, format specifiers only change how these numbers are displayed, so for example, when using %x the value is printed as an unsigned hexadecimal integer, and when using %d it is printed as a signed decimal integer. If you’d like to know more about printf() you can read about it here.

2

solved In the following code, I’m confused as to what their values are. Could I get some help here, please? [closed]