News for hackers. Stuff that matters.
Re:A convenient untruth: Array notation in C is a lie by coldpie on Thursday December 22, 2016 @11:15AM (#13238204)
> Isn't the proper type of a string literal the following?

No, it's a const char pointer. Your declaration actually makes a copy of the "Hello world" string into a new char array, distinct from the string literal itself:

  [~]$ cat test.c
  #include <stdio.h>
  
  int main(int argc, char ** argv)
  {
      char a[] = "test2";
      printf("sizeof(a): %lu\n", sizeof(a));
      return 0;
  }
  [~]$ gcc -std=c99 -pedantic -Wall -o test test.c
  [~]$ ./test
  sizeof(a): 6
  [~]$
Re:A convenient untruth: Array notation in C is a lie by copascetic on Thursday December 22, 2016 @12:41PM (#13238870)
The type of a string literal is array of char, and like other arrays, they decay to pointers to the first element when used in expression context, with three exceptions: sizeof, taking the address with &, and when used as a string initializer. "test2" in your example is not a const char *, it's an initializer, since this is one of the exceptions to array-to-pointer decay.

http://c-faq.com/aryptr/aryptrequiv.html http://c-faq.com/decl/strlitinit.html