Program to print values in variables using pointers is a simple program to print value of variable using pointer.

Pointers in c
The pointer is a variable that stores address of another variable.
Syntax for pointers in c
<Datatype> *pointername;
In the above syntax, the data type is the type of variable we want to store pointer.
And pointer name is the name of a pointer variable, * indicates it’s pointer variable.

Example:- int *ptr;

Accessing the value of a variable:-
We can access the value of a variable by using the variable name or by the address of the variable. we can access the value by using a pointer as it stores the address of the variable.
& Address of the operator gives the address of the variable.
* gives the value at that address stored in the pointer variable.

Algorithm to print values using a pointer

  1. Declare variable and Pointer variable.
  2. Print values in variable

Program to print values in variable using Pointers

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
main()
{
int i,*j,**k;
i=5;
j=&i;
k=&j;
printf("Values in variables\n");
printf("Value in i %d\n",i);
printf("Value in j which is the address of i %d\n",j);
printf("Value in k which is the address of j %d\n",k);

//printing using pointer
printf("Using Pointers\n");
printf("Value in i %d\n",*(&i));
printf("Value in i %d\n",*j);
printf("Value in i %d\n",**k);
printf("Value in j %d\n",*(&j));
printf("Value in j %d\n",*k);
printf("Value in k %d\n",*(&k));
}

Output :

Print values in variables using pointers

Write A Comment