Showing posts with label 2d pointers. Show all posts
Showing posts with label 2d pointers. Show all posts
Wednesday, November 13
Two Dimension Pointers C++
Pointers are very useful construct of C++ programming language and what is more useful is 2d pointers.
The pointers are special variables pointing to a memory location or a variable where as an array is a collection of those variables. A 2d pointer is a pointer which is pointing to array of pointers.
e.g.
The pointers are special variables pointing to a memory location or a variable where as an array is a collection of those variables. A 2d pointer is a pointer which is pointing to array of pointers.
e.g.
//Assign an array of 5 nameless pointers to a 2d pointer
int **pointer = new int*[5];
//then assign values to each array
for(int i=0;i<5; i++)
{
pointer[] = new int[10];
}
//now we have a 2d pointer which can be also accessed as array
pointer[2][9] ; //this is third row and 10th element










