Does the = (assignment) get me a copy of the content or points me to the same location in memory? For some reason, I end up thinking that what the code does is not setting y = 44 in a separate memory location but rather point to x
#include <stdio.h>
#include <cs50.h>
int main(void)
{
int x = 1;
int y = 44;
// Print Address and Value of x
printf("%p\n",&x);
printf("%i\n",x);
// Print Address and Value of y
printf("%p\n",&y);
printf("%i\n",y);
y = x;
// Add Separator
printf("------------------\n");
printf("%p\n",&x);
printf("%p\n",&y);
if (x==y)
{
printf("YES\n");
}
}
WHICH gives me the following on the command line
0x7fff5a5e8cb8
1
0x7fff5a5e8cb4
44
------------------
0x7fff5a5e8cb8
0x7fff5a5e8cb4
YES
EDIT: I am noting a different behavior with Python. Once I set y=a I am getting the same memory location. When updating y I expected a to also change but that doesn't happen.