I just learned about the cstring and some functions in cstring library. When I tried to use the function strcpy, I got a confusing problem. Can anyone thoroughly explain to me why the first code doesn't work while the second one runs totally fine?
First code:
  char *str1 = "hello";
  char *str2 = "hi";
  strcpy(str1, str2);
  cout << str1;
Second code
   char str1[] = "hello";
   char *str2 = "hi";
   strcpy(s1,s2);
   cout << str1;
I guess the problem is how I declare the variable str1 but I still have no idea why it doesn't work when str1 is a pointer.
 
    