The first, I assume, is a pointer to a zero terminated string constant.
The second, is a pointer to the first zero terminated string constant in an array of them?
So, could I say name = names[0]?
Could I say char ** newNames = names ?
How about creating a reference type for the second declaration (char * names[]).
I'm a little confused because the second type seems to be a pointer of pointers, so to speak, and I can't fully put this in my head.
char *name is the same as char name[]
char *names[] is the same as char names[][]
No, this is misleading. Arrays are not pointers. Arrays can be converted to pointers, but they are not pointers.
1 2 3
char *x = "foo"; // error: conversion from const char[] to char* discards qualifiers
char y[] = "foo"; // okay: aggregate initialization
// y has the array type char[4]
How about creating a reference type for the second declaration (char * names[]).
1 2
// reference to array of 4 pointers to char
char* (&rnames)[4] = names;
No, this is misleading. Arrays are not pointers. Arrays can be converted to pointers, but they are not pointers.
Yes, my bad, I meant in the context of your code. char *x is what your array would decay to if you were to pass it into a function. You can still use it as if it were an array to an extent through "[]".
You can use [] until you have a good reason not to. If you're doing this to learn, then my advice doesn't apply.
EDIT: constchar *x = "foo"; - Would work
^ Some compilers will run it even without the "const", but it may give you a warning.
They both generate data in memory, {h,e,l,l,o,/0}. The fundamental difference is that in one char* you are assigning it to a pointer, which is a variable. In char[] you are assigning it to an array which is not a variable. ... char* is a variable.