Solution for Exercise 19-10
ex1910
#include <stdio.h>
int main()
{
char alpha = 'A';
int x;
char *pa;
pa = α /* initialize pointer */
for(x=0;x<26;x++)
putchar((*pa)++);
putchar('\n');
return(0);
}
Output
ABCDEFGHIJKLMNOPQRSTUVWXYZ
Notes
* The (*pa)++
notation demonstrates the power of pointers. It illustrates how the same variable can both manipulate a value at a location and potentially change locations as well.
* You need to specify parentheses with (*pa)++
because the *pa++
operation would represent the value at location pa
, but then increment pa
. Instead, (*pa)++
affects only the value at pa
.
* This example, specifically Line 12, also shows you how pointer notation can get entirely confusing with little effort.
Copyright © 1997-2024 by QPBC.
All rights reserved