C++ Pointer

In C++ language pointer is a variable the stores/points the address of another variable. The pointer is used to allocate memory dynamically. Another variable can be of type int, char, array function, or any other pointer. We declare a pointer like this:-

The pointer can be declared in many types some of them are:-

  • Pointer to an integer
  • Pointer to a character
  • Point to a float

We do many things with pointer like:-

  • Define a pointer Variable
  • Assign the address of a variable to a pointer
  • Access the value of the pointer variable.

We do many things with pointer like:-

  • Define a pointer Variable
  • Assign the address of a variable to a pointer
  • Access the value of the pointer variable.

Passing a pointer to an Array

Pointer to an array is basically a pointer that points to the address of the first element of the array.

Passing a pointer to a function

Passing a pointer as an argument instead of a variable then the address of the variable is passed instead of the value. So, the function using the pointer is permanently made at the address of the passed variable. This is call by reference.

Passing a pointer to a function

A pointer holds the address of another variable of the same data type. When a pointer holds the address of another pointer then such type of pointer is known as pointer-to-pointer or also known as double pointer.

Syntax-