Monday, April 1, 2013

Playing with pointers

Just a silly program playing with pointers

/* Problem: This is just a silly program playing with pointers */

#include <stdio.h>

int
main (void)
{
   /* a and e are integers */
   int a, e;  

   /* b is a pointer to an integer */
   int* b; 

   /* c is a pointer to a pointer to an integer */   
   int** c;

   /* d is a pointer to a pointer to a pointer to an integer */
   int*** d;     
 
   a = 25;   /* a contains the integer 25 */
   b = &a;   /* b contains the address of a */
   c = &b;   /* c contains the address of b */
   d = &c;   /* d contains the address of c */

   /* Do you understand that ***d is actually a? */
   e = ***d * 2;   
 
   printf ("%d", e);
 
   return (0);
}
 


Legend: preprocessor directives | variable declarations | main program | helper functions | user-defined structures | comments
50

No comments:

Post a Comment