Q:

Write a C Program to dereference pointer variables

0

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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 .

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C Pointer Solved Programs – C Programming

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a C Program to show an example of pointer to... >>
<< Write a C Program for Addition of Two Numbers Usin...