Hi

int** numberLists = new int*[count];

I'm having difficulties understanding this line of code, I've just started programming in c++.

I think I got the basics of pointers but I can't find any helpful "enough" info about arrays of pointers.

I understand that an array of pointers to integers is assigned to variable numberLists which is a pointer to a pointer to an integer. Unfortunately that doesn't get me very far.

Thanks.

Recommended Answers

All 3 Replies

My best guess, without seeing this in context, is that it is to define a two-dimensional array. It is very unlikely that you will see pointers to single ints (unless you're trying to pass them by reference the 'C' way). In this case, you have one large array with lots of pointers in it. Each one of the "smaller" pointers actually refers to another array. That way you have two dimensions represented.

Thanks for the quick reply, it's starting to make more sense :>
Okay so lets say I declare it as follow:

int** numberLists = new int*[2];

How do I access and fill the "2d" array with the following integers:

2 4
6 8

I'm really confused :S

Ignoring the task of initialization (for now), you would access it like so: numberLists[row][col]; . To get the number 4 for example, the code would be numberLists[0][1]; (1st row, 2nd column).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.