Hello, Hussain K.
The answer to your question is "because of types". Please allow me to explain. The last 2 statements are:
The first of these does the following:
- Take the address of the int reached by the expression `ptr->num`.
- Dereference the address of the int, returning an int.
- Send the int to cout.
The second of these does something similar, but different:
- Take the address of the Node * reached by the expression `ptr->next`.
- Add 1 to the address of the Node *, returning the address of another Node *(!)
- Dereference the address of the Node *, returning a Node *(!)
- Send the Node * to cout.
So, the first is streaming the value of an int (which defaults to decimal), and the second is streaming the value of a (Node *) pointer (which defaults to hexadecimal). Even though the addresses being dereferenced are the *same*, the *types* are different, as is the behavior of the stream conversion of int/pointer to characters.
I hope this clears it up for you. Please comment if you're not comfortable with my explanation.
Hussain K.
i don't know if the priority is the case here cout << *(&ptr->num) << "\n"; cout << *(&ptr->next + 1) << "\n"; because the last two lines are almost same num = next + 1 but when print it first value appear decimal and the second hexadecimal02/23/20