Pointers in C Programming – Basics

Pointers in C Programming – Basics

DATA STRUCTURES IN C – LINKED LIST (20 PROGRAMS)

Pointers in C Programming – Basics :

Source Code :

#include<stdio.h>
int main()
{
    int a=5;
    int *ptr;
    //Declaring a integer pointer variable which can point to a address of integer

    ptr=&a;
    //Pointer variable ptr will now point to the address of integer variable a
    //Pointer variable stores the address location of integer variable a

    printf("\na=%d",a); 
    printf("\n*ptr=%d",*ptr); 
    //*ptr will print the value present at the location where the pointer ptr is pointing to

    printf("\nAddress of a=%d",&a);
    //Address of variable a 

    printf("\nptr=%d",ptr);
    //Address of variable a is equal to pointer variable a 
    //Value present in pointer variable ptr

    printf("\nAddress of pointer variable ptr=%d",&ptr);
    //Address of pointer variable ptr

    return 0;
}

Output :

a=5
*ptr=5
Address of a=2293532
ptr=2293532
Address of pointer variable ptr=2293528

[ YOU MAY ALSO LIKE ]

Leave a Reply