Pointer in C programming

mujahida_joynab_64c7407d8

Mujahida Joynab

Posted on November 4, 2024

Pointer in C programming

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) ;
}
Enter fullscreen mode Exit fullscreen mode

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) ;

Enter fullscreen mode Exit fullscreen mode

}
Output - 1

💖 💪 🙅 🚩
mujahida_joynab_64c7407d8
Mujahida Joynab

Posted on November 4, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related