Professional Documents
Culture Documents
A pointer is a variable that contains a memory address as its value. It contains an address of a variable
that contains a specific value.
Example:
int *ptr; /*means ptr is a pointer to an integer value*/
The data type indicates what type of variable the pointer is allowed to point to. Thus, if a pointer has to
point to a character, the data type of the pointer should be char. For the above example, ptr can only
point to an integer variable.
Indirection
Pointer Operators
1. Address operator (&) – a unary operator that returns the address of its operand.
Example:
int y = 5;
int *yptr;
yptr = &y; /* assigns the address of the variable y to pointer variable yptr */
Illustration:
Since yptr holds the address of y, yptr points to y. Thus, it can indirectly access the value of y. In other
words, a pointer points to a variable if it holds the address of that variable.
2. Indirection operator (*) – also known as dereferencing operator. It returns the value of the object
to which its operand (i.e., a pointer) points.
Example:
To display the address of a variable or the value of a pointer, use %p conversion specification.
Sample Program:
Output:
Open the link below to understand pointers more.
https://www.youtube.com/watch?v=47IS8VtAM9E