Print values in variables using pointers is a simple program to print value of variable using pointer.
In this tutorial we are going to learn pointers in c, how to access value of variable using pointer variable, Print values in variables using pointers and program to print values in variable using pointers.
what is pointers in c
Pointer is a variable which stores address of another variable.
syntax for pointers in c
In above syntax, data type is type of variable we want to store pointer.
And pointername is name of pointer variable, * indicates it’s pointer variable.
Example :- int *ptr;
Accessing value of variable:-
We can access value of variable by using variable name or by address of variable.we can access value by using pointer as it stores address of the variable.
& Address of operator gives the address of variable.
* gives the value at that address stored in pointer variable.
Concept you need to know from c
1. Basic input and output in c
2. pointers in c
Algorithm to print values using pointer
2. Declare variable and Pointer variable
3. Print values in variable
Program to print values in variable using Pointers
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("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));
1. Write header files to file.
2. Start with writing main function.
3. Declare variable
i => int variable
j => pointer variable
k => pointer to pointer
4. Print actual value stored in variable
i = 5
j = 1000 => address of i (address can be anything)
k = 2000 => address of j (address can be anything )
5. We can print value i in different way as *(&i), *j, **k
6. To print value in j we write *(&j), *k
7. And to print value in k we write *(&k)