The CPP Programming Lanuage chapter 5, exercies 3, use typedef to define pointer to arrays.
Does pointer to array exist ?
I tried
typedef (char *pchar_array)[];
but the compiler give the error: syntax error : ')'.
When I learned C, I learn that if I defined int a[10], a is only a symbol of address, not an object. But in VC, &a is valid and has the same value as a itself. Is C++ different from C at this point ?
#include <vector>
usingnamespace std;
int a[10]; // C array: chunk of contiguous memory
int (*b)[10]; // pointer to a chunk of contiguous memory
vector<int> c( 10 ); // C++ array: an object - memory allocated through a constructor
vector<int>* d; // pointer to an object
Think of a being an address as a convenience that the C language offers you, so you don't have to type &a[0]. Whenever you get confused, ask yourself: how much memory has just been allocated with my declaration?
In general, for simplicity, you can think of C++ is a superset of C, with some caveats: