A brief question to do mainly with understanding how pointers work with arrays in this example:
char *lineptr[MAXLENGTH]
Now I understand this is the same as char **lineptr as an array in itself is a pointer.
My question is how it works in its different forms/ de-referenced states such as:
lineptr
*lineptr
**lineptr
*lineptr[]
In each of those states, whats happening, what does each state do/work as in code?
Any help is much appreciated!
No, an array is not the same as a pointer. See the C FAQ: http://c-faq.com/aryptr/index.html.
This is the array itself. In most situations, it decays into a pointer to its first element (i.e.
&lineptr[0]). So its type is eitherint *[MAXLENGTH]orint **.This dereferences the pointer to the first element, so it’s the value of the first element (i.e. it’s the same as
lineptr[0]). Its type isint *.This dereferences the first elements (i.e. it’s the same as
*lineptr[0]). Its type isint.I don’t think this is valid syntax (in this context).