Hi! Can anyone please explain the difference between int* p and int** p?
int*: Pointer to an int.
int**: Pointer to a pointer to an int (pointer to an int*).
int***: Ponter to a pointer to a pointer to an int (pointer to an int**).


Last edited on
Have you ever tried creating shortcut to shortcut to a document?
There is a program in Program Files/Program/start.exe (that would be int).
There is a shortcut to that program on Start Menu (that would be int*).
Then the user created a shortcut to the file in Start Menu, that is a shortcut to shortcut to file (that would be int**).
Last edited on
I actually was making a hash table in which a pair was defined using template class as below:

template <class K, class E>
class hashTable
     pair<const K, E>** table;
     int dSize;
     int divisor;
     hash<K> h;    // hash is a class to convert string to integer

     // other functions

here it treats table as an array. I am confused how is it defined as array and whether it is a pointer array or just array??
And thanks for the help.. :)
Your table member is defined as a pointer to a pointer to a pair<K, E>. However, pointers can freely point to elements within an array. Usually, a programmer will maintain a pointer to the first element of the array so that they can use the [] notation to get its elements. When you dynamically allocate an array, you're basically allocating a block of memory and making the pointer point to the first element.

A 2D array like you're trying to make (I presume), is, in reality, an array of pointers to arrays. When you allocate a 2D array, you're setting that pointer to point to the first element of an array of pointers, each pointer in turn pointing to the first element of an array of pairs.

Does that help at all?

Does it mean if i make a pointer p point to an the first element of an array, i can access the elements by p[]??

int a[10];
int *p;
p = a;
int x = p[5];     // is this correct?? 

Topic archived. No new replies allowed.