II-188 Programming Concepts
4. Explain the use of (*) indirection operator.
Ans: Pointer variables are declared as follows:
The indirection operator (*) is also called the dereferencing operator. When a pointer is dereferenced,
the value at that address stored by the pointer is retrieved.
The indirection operator (*) is used in two distinct ways with pointers, declaration and dereference.
1. When a pointer is declared, a star (*) indicates that it is a pointer and not a normal variable.
2. When the pointer is dereferenced, the indirection operator indicates that the value at that memory
location stored in the pointer is to be accessed rather than the address itself. For example,
printf('%d',*x); will print the value of another variable stored in memory location x.
5. Write a program to display the value of a variable and its address using pointer.
printf("\n Address of v = %u",p);
printf("\n Value of v = %d",*p);
printf("\n Address of p = %u",&p);
Address of v = 4060
Value of v = 10
Address of p = 4062
Explanation: In the above program, ‘v’ is an integer variable and its value is 10. The variable ‘p’ is
declared as pointer variable. The statement p = &v assigns address of ‘v’ to ‘p’, i.e., ‘p’ is the pointer to
variable ‘v’. To access the address and value of ‘v’, pointer ‘p’ can be used. The value of ‘p’ is nothing
but address of variable ‘v’. To display the value stored at that location, *p is used. The pointer variables
also have an address and displayed using ‘&’ operator. The statement used is printf("\n Address
of p = %u", &p);. The above explanation is followed by Figure 9.1.
M09_ITL-ESL4791_02_SE_C09.indd 188 12/22/2012 5:04:01 PM