Pointers

Pointers are variables that stores the address of other variables. Data type of pointer is same as that of the variable of which address it is storing.

Before exploring examples, we need to know about “&” and “*”.

Address Of Operator

& is called the address of operator. It creates reference to a variable. When we put &-sign before a variable name, it gives us the address/reference of that variable in computer memory. The result we get is the hexadecimal value. As there is only one operand, it is called unary operator.

Dereference Operator

"*" is called dereference operator. When we put * sign before a pointer variable, it dereferences it or we can say it gives us the data value at that address pointer is storing. struct is declared outside the main function.

Declaring a pointer

Pointers with Arrays

Syntax for declaring array pointer is same as int or any other pointer.

Accessing array members using pointers

Pointer to Pointer

Pointers are variables which store the address of another variable with the same data type. Pointers can also store the address of another pointer (variable). These are called pointer to pointer.

Note: You can declare variables of type void which store address of variable with any data type.

Practice Exercises

Complete these exercises to reinforce your learning and earn XP

Sign in to track your progress and earn XP!
Exercise 1 of 2Medium

What operator is used to get the address of a variable?

15 XP~3 min
Exercise 2 of 2Medium

What operator is used to dereference a pointer?

15 XP~3 min