C Programs | IT Developer
IT Developer

C Programs



Share with a Friend

Pointers in C

Pointer Basics (address, value)

C Program: Pointer Basics: Display Address and Value

C

#include <stdio.h>

 

int main() {

    int a = 10;       // integer variable

    int *ptr;         // pointer variable

 

    ptr = &a;         // store address of 'a' in pointer

 

    printf("Value of a: %d\n", a);

    printf("Address of a: %p\n", &a);

    printf("Value of ptr (address stored in ptr): %p\n", ptr);

    printf("Value pointed by ptr: %d\n", *ptr);

 

    return 0;

}

Output

 
OUTPUT :
Value of a: 10
Address of a: 0x7ffeefbff56c
Value of ptr (address stored in ptr): 0x7ffeefbff56c
Value pointed by ptr: 10

Explanation

  • a is a normal integer variable.
  • ptr is a pointer variable that holds the address of a.
  • &a gives the memory address of a.
  • *ptr gives the value stored at the address that ptr points to.