0

How does p = q; *p = 2; work?

I don't understand how q is reassigned a new number. https://code.sololearn.com/cOaDKp7u4ilw/?ref=app

21st Jan 2021, 11:15 PM
silentlearner
silentlearner - avatar
4 Réponses
+ 2
Here is what the program is doing: (int *p) p is a pointer, it stores the memory address of i (int *q) q is a pointer, it stores the memory address of j (p=q) now p stores the same value stored by q: the memory address of j (*p=2) the memory address pointed by p now stores 2, that means j=2
21st Jan 2021, 11:46 PM
Angelo
Angelo - avatar
+ 1
Yes, if you want check out this too https://www.sololearn.com/post/897320/?ref=app
23rd Jan 2021, 1:18 PM
Angelo
Angelo - avatar
23rd Jan 2021, 12:31 PM
silentlearner
silentlearner - avatar
0
Thank you, Angelo.
23rd Jan 2021, 1:24 PM
silentlearner
silentlearner - avatar