Pointer in C

tutorial and example
tutorial and example

Pointer is a variable that is used to contain the address of another variable. We can easily create pointer in C language.

Example: int *ptr

Symbol Description
& (ampersand sign) Address of operator is used to contain the address of a variable.
* (asterisk sign) Indirection operator is used to accesses the value at the address..

Advantage of pointer

In C language,there are various advantages of pointer that are given below:

  • It is used to reduce the code and performance.
  • It accesses the direct address of variable.
  • It is used to return multiple values from function.
  • It helps us to access any memory location from pointer.

      How can we declare pointer

We can declare pointer by using * (astric symbol).

Syntax:

Let us consider an example:

Null Pointer

A pointer does not assign any value that is known as NULL pointer. We can create null pointer at the time of declaration.

Example: int *ptr=NULL: