Pointer is a variable that indicates address of another variable .
To indicate the address of a variable –
#include<stdio.h>
int main(){
int arr[5] = {1,2,3,4,5} ;
int *p = &arr[0] ; // p is initialized as the address of arr[0]
printf("%d \n", p) ;
}
Output –
6422016 //The address vary each time the program runs.
Indicating the address of a variable with pointer is called referencing.
Indicating the value of the variable with pointer is called dereferencing .
Code for dereferencing
#include<stdio.h>
int main(){
int arr[5] = {1,2,3,4,5} ;
int *p = &arr[0] ;
printf("%d \n", *p) ;
}
Output - 1
Top comments (0)