Write a C Program to dereference pointer variables

By | 19.03.2017

C Program to dereference pointer variables


Write a C Program to dereference pointer variables. Here’s a Simple Program which intialize any variable and points any pointer to it and then dereference pointer variables in C Programming Language.


Dereference Pointer in C :


Dereferencing a pointer means getting the value that is stored in the memory location pointed by pointer. * operator is used along with pointer variable while Dereferencing the pointer variable.

When used with Pointer variable, it refers to variable being pointed to,this is called as Dereferencing of Pointers

Dereferencing Operation is performed to access or manipulate data contained in memory location pointed to by a pointer.Any Operation performed on the de-referenced pointer directly affects the value of variable it pointes to.


Below is the source code for C Program to dereference pointer variables which is successfully compiled and run on Windows System to produce desired output as shown below :


SOURCE CODE : :


/* Program to dereference pointer variables*/

#include<stdio.h>
int main( )
{
        int a = 87;
        float b = 4.5;
        int *p1 = &a;
        float *p2 = &b;
        printf("Value of p1 = Address of a = %p\n", p1);
        printf("Value of p2 = Address of b = %p\n", p2);
        printf("Address of p1 = %p\n", &p1);
        printf("Address of p2 = %p\n", &p2);
        printf("Value of  a = %d  %d  %d \n", a , *p1, *(&a) );
        printf("Value of  b = %f  %f  %f \n",  b , *p2, *(&b));

    return 0;
}

OUTPUT : :


Value of p1 = Address of a = 000000000062FE4C
Value of p2 = Address of b = 000000000062FE48
Address of p1 = 000000000062FE40
Address of p2 = 000000000062FE38
Value of  a = 87  87  87
Value of  b = 4.500000  4.500000  4.500000

Above is the source code for C Program to dereference pointer variables which is successfully compiled and run on Windows System.The Output of the program is shown above .

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach upto you in the short interval.


Thanks for reading the post.

5 1 vote
Article Rating
Category: C Programming Pointer Programs Tags:

About Tunde A

My name is Tunde Ajetomobi, a Tech Enthusiast and Growth Hacker. I enjoy creating helpful content that solves problem across different topics. Codezclub is my way of helping young aspiring programmers and students to hone their skills and find solutions on fundamental programming languages.

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments