differences in the declaration

1/ What is the differences between int *p[10], int **p = new int*[10] and int p[10].

2/ What is the differences between int *arr[10], int (*arr)[10], int *(arr[10]).


int *p[10] declares p as an array of 10 pointers to int

int **p = new int*[10] allocates memory, constructs an array of 10 pointers to int in that memory, declares p as a pointer to pointer to int, and initializes it to point to the first of the 10 pointers to int that were allocated.

int p[10] declares p as an array of 10 int

int *arr[10] declares arr as an array of 10 pointers to int

int (*arr)[10] declares arr as a pointer to an array of 10 int

int *(arr[10]) declares arr as an array of 10 pointers to int (same as int *arr[10])

You should like http://cdecl.org - it will explain these and more complex C declarations
so when i declare like that, where is the location of variables in memory? They have the address next or far to each others ?
Topic archived. No new replies allowed.