What is pointer? - C++

What is pointer? Explain with examples.

- A pointer is a variable that holds a memory address. This address is the location of another object (typically, a variable) in memory. That is, if one variable contains the address of another variable, the first variable is said to point to the second.
- A pointer declaration consists of a base type, an *, and the variable name.
- The general form of declaring a pointer variable is :
type *name;
-The 'type' is the base type of the pointer and may be any valid type.
- The 'name' is the name of pointer variable.
- The base type of the pointer defines what type of variables the pointer can point to.


- Two special pointer operators are: * and &.
- The & is unary operator that returns the memory address of its operand. It is “the address of” operand.
- The * is complement of &. It is also a unary operator and returns the value located at the address that follows.
int i, *p;
i = 5;
p = &i;   //places the memory address of i into p
The expression *p will return the value of variable pointed to by p.
Pointer to constant vs. pointer constant - C++
Pointer to constant vs. pointer constant - Pointer to constant points to a value that does not change and is declared....
What are function pointers?
What are function pointers? - A function has a physical location in the memory which is the entry point of the function...
What is pointer to member? - C++
What is pointer to member? - This type of pointer is called a pointer to a class member or a pointer-to-member....
Post your comment