0

Pointers

whats is the point of knowing where a variable is stored in memory? I can't see where i would need to know that.

20th Jan 2018, 8:43 AM
Lionel Brown
Lionel Brown - avatar
2 Answers
+ 3
When you store elements inside a contiguous memory like in an array, you require a way to access any element inside the array. This is when knowing the addresses of some elements help. You simply note the first element's address, and use that to get the successive elements by simple incrementation, as all of them are in contiguous locations (one after the other). This is simply what happens inside the [] operator's code, and this is the reason array elements start with 0. Thus, knowing the address helps store similar elements together.
20th Jan 2018, 2:18 PM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 1
your variables are stored somewhere in the memory, how would you dereference it if you don't know where it is?
20th Jan 2018, 9:18 AM
shobhit
shobhit - avatar