ptr to array vs. array of ptrs

If I understand correctly, the following is an array of pointers to int:

int *nums[2];

How does one define a pointer to an array of ints in one line? Can this be done? Or does it have to be:

1
2
int nums[2];
int *p_nums = nums;
Another way would be int* p_nums = new int[2];
see http://www.cplusplus.com/doc/tutorial/dynamic/
I have an exercise in a book I'm reading that wants me to 'typedef' a pointer to an array of char, which is what I'm really getting at. This leads me to believe it can be done in one line without using 'new' because the book has not introduced 'new' yet (though I know what it does).
A typedef isn't actually creating any variables. It just defines another way to refer to a type.

typedef char SomeType;

Now you can use SomeType just like you would the type char. It does not actually create any char's or anything; it just let's you use that name instead.
Example - pointer to array of 5 integers:

int (*ptr_name)[5];

Note: pointers to different sized arrays are considered different types.

1
2
3
4
5
6
int array1[4];
int array2[6];

int (*ptrIntArray1)[4] = &array1;
int (*ptrIntArray2)[6] = ptrIntArray1; //Error cannot convert from 'int (*)[4]' to 'int (*)[6]' Need a cast
Right. I understand typedef'ing and I understand pointers to arrays. What I don't understand is how to combine the two so that I can typedef a pointer to an array of <type>.
uhm.. typedef int (*my_pointer)[4];
Topic archived. No new replies allowed.