Docsity

Understanding Pointers to Pointers and Double Dereferencing in C, Exercises of Computer Fundamentals

Toggle sidebar
bg1
#include <stdlib.h>
#include <stdio.h>
/*
* This program basically demonstrate how to use pointer to a pointer and
* use of double dereference operator.
*/
int main (int argc, char *argv[])
{
int i,a=0;
int *ptr_a; // pointer to int
int **ptr_ptr_a; // pointer to a pointer of type int
//code to see double dereferencing.
printf("Memory address of a is %p \n",&a);
ptr_a=&a; // ptr_a points to variable a
printf("ptr_a stores Memory address of a is %p\n",ptr_a);
printf("Memory address of ptr is %p\n",&ptr_a);
*ptr_a=5; // changing value of a using ptr_ptr_a
printf("\n printing value using ptr_a a=%d \n",*ptr_a);
ptr_ptr_a=&ptr_a; // ptr_ptr_a points to another pointer ptr_a
printf("ptr_ptr_a stores Memory address of ptr_a is %p\n",ptr_ptr_a);
printf("Memory address of ptr_ptr_a is %p\n",&ptr_ptr_a);
**ptr_ptr_a=11; // changing value of a using ptr_ptr_a
printf("\n printing value using ptr_ptr_a a=%d \n",**ptr_ptr_a);
return 0;
}
docsity.com

Partial preview of the text

Download Understanding Pointers to Pointers and Double Dereferencing in C and more Exercises Computer Fundamentals in PDF only on Docsity!

#include <stdlib.h> #include <stdio.h> /*

  • This program basically demonstrate how to use pointer to a pointer and
  • use of double dereference operator. */ int main (int argc, char *argv[]) { int i,a=0; int *ptr_a; // pointer to int int **ptr_ptr_a; // pointer to a pointer of type int //code to see double dereferencing. printf("Memory address of a is %p \n",&a); ptr_a=&a; // ptr_a points to variable a printf("ptr_a stores Memory address of a is %p\n",ptr_a); printf("Memory address of ptr is %p\n",&ptr_a); ptr_a=5; // changing value of a using ptr_ptr_a printf("\n printing value using ptr_a a=%d \n",ptr_a); ptr_ptr_a=&ptr_a; // ptr_ptr_a points to another pointer ptr_a printf("ptr_ptr_a stores Memory address of ptr_a is %p\n",ptr_ptr_a); printf("Memory address of ptr_ptr_a is %p\n",&ptr_ptr_a); ptr_ptr_a=11; // changing value of a using ptr_ptr_a printf("\n printing value using ptr_ptr_a a=%d \n",ptr_ptr_a); return 0; }

docsity.com