Monday, April 1, 2013

Understanding pointers

This program just demonstrates how to assign values to pointer variables. It serves no other purpose.


/* Problem: This program just demonstrates how to assign values 
to pointer variables. It serves no other purpose. */

#include <stdio.h>

int
main (void)
{
 /* c and d are pointers to integers */
 int a, b, *c, *d, e;

 a = 10;
 b = a * 3;
 c = &a; /* address of a goes into c */
 d = &b; /* address of b goes into d */
 e = *c + *d; /* *c is a and *d is b */
 *d = a;
 d = &a;
 *c = *d - a % b + *c;

 printf ("Do you understand why\n");
 printf ("a= %d, b= %d, e= %d ?\n", a, b, e);

 return (0);
}

Legend: preprocessor directives | variable declarations | main program | helper functions | user-defined structures | comments
Do you understand why
a= 20, b= 10, e= 40 ?

No comments:

Post a Comment