31 January 2022

Print Address of variable Using Pointers

 Question :

Write a program to print the address of a variable. Use this address to get the value of this variable.

#include<stdio.h>
 
int main()
{
    int a = 111;
    int *ptr;
    ptr = &a ;
   
    printf("The address of variable a is : %u\n", &a);
    printf("The value of variable a is : %d\n", *(&a));
    printf("The value of variable a is : %d\n", *ptr);

 
return 0;
}

OUTPUT--->

The address of variable a is : 6422216 The value of variable a is : 111 The value of variable a is : 111




  

No comments:

Post a Comment