News for hackers. Stuff that matters.
Re:C Strings and my slow descent to madness by gpderetta on Thursday April 06, 2023 @10:21AM (#35468650)
I don't see any mention or insinuations of arrays-are-pointers anywhere in the article. Am I missing something?
Re:C Strings and my slow descent to madness by coldpie on Thursday April 06, 2023 @10:38AM (#35468888)
This bit:

    But you might be asking. “Why can’t I just assign the source variable directly to the destination variable?”

    int main() {
      char source[] = "Hello, world!";
      char* destination = source;
    
      strcpy(destination, source); // Copy the source string to the destination string
    
      printf("Source: %s\n", source);
      printf("Destination: %s\n", destination);
    
      return 0;
    }
    You can. It’s just that destination now becomes a char* and exists as a pointer to the source character array. If that isn’t what you want them this will almost certainly cause issues.