Hi, I have a piece of code here.
#include <stdio.h>
int main()
{
// jimmy and masked_raider are just aliases for the same memory address. They’re pointing to the same place
char masked_raider[] = "Alive";
char *jimmy = masked_raider;
printf("Masked raider is %s, Jimmy is %s\n", masked_raider, jimmy);
masked_raider[0] = 'D';
masked_raider[1] = 'E';
masked_raider[2] = 'A';
masked_raider[3] = 'D';
masked_raider[4] = '!';
printf("Masked raider is %s, Jimmy is %s\n", masked_raider, jimmy);
jimmy[0] = 'N';
jimmy[1] = 'O';
jimmy[2] = '\0';
printf("Masked raider is %s, Jimmy is %s\n", masked_raider, jimmy);
jimmy = "not ok";
printf("Masked raider is %s, Jimmy is %s\n", masked_raider, jimmy);
return 0;
}
My problem is after change the value of Masked raider the jimmy changed,but when set jimmy = "not ok";
Masked raider did not change,how to explain it?