A pointer is an address. It is a derived data type that stores the memory address. A pointer can also be used to refer another pointer, function. A pointer can be incremented/ decremented, i.e., to point to the next/ previous memory location.
data_type * pointer_variable_name; Here, • data_type is the pointer's base type of C's variable types and indicates the type of the variable that the pointer points to. • The asterisk (*: the same asterisk used for multiplication) which is indirection operator, declares a pointerInitialize a pointer
pointer = &variable;
Program:
#include <stdio.h>
int main(){
int a=10; //variable declaration
int *p; //pointer variable declaration
p=&a; //store address of variable a in pointer p
printf("Address stored in a variable p is:%x\n",p); //accessing the address
printf("Value stored in a variable p is:%d\n",*p); //accessing the value
return 0; }
Output:
Address stored in a variable p is:60ff08
Value stored in a variable p is:10
| Topic | View/Download |
|---|---|
| More about pointer | View |