Problem 54

author
By Supreme2023-03-16
Problem Statement :
Write a program to print address of variable using pointer.
Code:

#include <stdio.h>

int main()
{

//54. Write a program to print address of variable using pointer.

printf("\t\tAddress Of Variable\n");
printf("================================================\n\n");

int x ;
int *ptr = &x;

printf("Enter The Value of X : ");
scanf("%d",&x);

printf("\n\n------------------------------------------------\n\n");
printf("The address of x is: %p\n", (void*)ptr);
printf("\n------------------------------------------------\n");

return 0;
}

Description :
  • This program is designed to print the address of a variable using pointers.
  • The program includes the standard input-output library stdio.h.
  • The main() function is defined and initialized.
  • An integer variable x is declared.
  • A pointer variable *ptr is declared of integer type, which is pointing to the address of the integer variable x.
  • The user is prompted to enter the value of x.
  • The address of x is displayed using pointer variable *ptr and formatted as a void pointer using %p format specifier.
  • The program returns 0, indicating successful execution.
Output Image:
Output-image

© Copyright 2022. All right reserved, GTU Coder.