Here is my code
char *sptr = "abc", *tptr;
*tptr = *sptr;
printf("ch = %c\n", *tptr);
Now, when we declare a pointer, no memory is allocated to store char variable. So, this code does run and 'a' is printed on the console. I know that "abc" is a string literal and its a read only memory. But when I execute *tptr = *sptr , where is *tptr is stored ?
>Solution :
The assignment *tptr = *sptr; invokes undefined behavior, since you’re storing through an undefined pointer. It’s a severe bug. Instead, you can do tptr = sptr;, which gives tptr the same value as sptr.