I'm working my way through Big Nerd Ranch's Objective C Programming (2nd Edition) and just came across this example in Chapter 15 (Objects and Memory):
NSDate *currentTime = [NSDate date]; //currentTime points to date object at some address ("A")
NSLog(@"currentTime's value is %p.\n", currentTime);
sleep(2);
currentTime = [NSDate date]; //currentTime now points to date object at different address ("B")
NSLog(@"currentTime's value is now %p.\n", currentTime);[/code]
I'd like to understand why currentTime changed from address A to address B when it was assigned a new date. Why didn't it write the data for the 2nd date into the memory location used for the 1st date (at address A)?
This c code (edit: which is embarrassingly bad but I will leave as originally-written so the comments/answers make sense):
int *i = 10;
i = 12;
doesn't change the value of &i or allocate any additional memory, so what gives?