arrays and pointers, char * vs. char [], distinction 
Author Message
 arrays and pointers, char * vs. char [], distinction

     I want to put it, that this is almost the *only* time what arrays
can be viewed as pointers:

"When the name of an array appear like an R-value, roughly an expression which
is not appearing immediately to the left of an assignment 'equal' sign,
then this name of an array can be treated by the programmer as a pointer
to the first element of an array."  The sizeof operator takes an L-value
or a type, not an R-value.


char c, text[5];

c = text[3]                     is              c = *(text + 3)


char *p, q[5];

p = text                        is              p = &(text[0])


q cannot be assigned = text


q[2] = text[2]                  is              *(q + 2) = *(text + 2)


sizeof p is size of pointer     but             sizeof q is size of array

                                                Daniel Chung (Mr.)

Sun, 01 Oct 1995 00:19:29 GMT  
 [ 1 post ] 

 Relevant Pages 

1. A char pointer (char *) vs. char array question

2. char pointer to 2D char array

3. Pointer vs array compile-time distinction (macros)

4. Converting char array of literals chars to escape chars

5. array declaration vs. char pointer

6. char[] vs char * vs #defines for constant strings

7. Differences between char array[SIZE] and char *array

8. Comparison with pointer to pointer to char, and char

9. char pointers vs. int pointers

10. char *c vs. char c[]

11. char **str vs. char *str[]

12. char * vs char[]


Powered by phpBB® Forum Software