Calling a pointer function in C++

Pointer Declaration
General Format:

data_type *pointer_name;

A pointer declaration such as,

int *numberPtr; 

declares numberPtr as a variable that points to an integer variable. Its content is a memory address.

The * indicates that the variable being declared is a pointer variable instead of a normal variable.

Consider the following declaration :

int *numberPtr, number = 20;  

In this case, two memory address have been reserved, associated with the names numberPtr and number.

The value in variable number is of type integer, and the value in variable numberPtr is an address for another memory location.

Example

// create a 2D array dynamically
int rows, columns, i, j;
int **matrix;
cin >> rows >> columns;
matrix = new int*[rows];
for(i=0; i<rows; i++)
   matrix[i] = new int[columns];

Leave a Comment