/* * A D D _ P T R * Demonstrate the declaration and the use of pinters */ int main(void) { int num1, num2, sum; /* declare var names */ int *np1, *np2, *sp; /* declare pointers to integers */ /* * Load ptrs with addresses of the declared variable */ np1 = &num1; /* Writes address of num1 in np1 */ np2 = &num2; /* Writes address of num2 in np2 */ sp = ∑ /* writes addres of sum in sp */ /* * Put values into memory locations pointed to by the ptrs */ *np1 = 5; *np2 = 7; *sp = *np1 + *np2; /* result is written in mem loc. pointed to by sp */ /* * Print out the adresses of the vars and their contents */ printf("\nName\t Address\t Value\n"); printf("\n----\t -------\t -----\n"); printf("%s\t%u\t%d\n", "number 1", &num1, *np1); printf("%s\t%u\t%d\n", "number 2", &num2, *np2); printf("%s\t%u\t%d\n", "sum ", &sum, *sp); printf("%s\t%u\t%d\n", "*np1 ", &np1, np1); printf("%s\t%u\t%d\n", "*np2 ", &np2, np2); printf("%s\t%u\t%d\n", "*sp ", &sp, sp); /* %s is for string fromat * %d is for decimal format * \n new line character * \t horizontal tab */ return (0); }