6. Arrays and Pointers

6.1 I had the definition char a[6] in one source file, and in another I declared extern char *a. Why didn't it work?

6.2 But I heard that char a[] was identical to char *a.

6.3 So what is meant by the ``equivalence of pointers and arrays'' in C?

6.4 Why are array and pointer declarations interchangeable as function formal parameters?

6.7 How can an array be an lvalue, if you can't assign to it?

6.8 What is the real difference between arrays and pointers?

6.9 Someone explained to me that arrays were really just constant pointers.

6.11 I came across some ``joke'' code containing the ``expression'' 5["abcdef"] . How can this be legal C?

6.12 What's the difference between array and &array?

6.13 How do I declare a pointer to an array?

6.14 How can I set an array's size at run time?

6.15 How can I declare local arrays of a size matching a passed-in array?

6.16 How can I dynamically allocate a multidimensional array?

6.17 Can I simulate a non-0-based array with a pointer?

6.18 My compiler complained when I passed a two-dimensional array to a function expecting a pointer to a pointer.

6.19 How do I write functions which accept two-dimensional arrays when the ``width'' is not known at compile time?

6.20 How can I use statically- and dynamically-allocated multidimensional arrays interchangeably when passing them to functions?

6.21 Why doesn't sizeof properly report the size of an array which is a parameter to a function?


top