Solution for Exercise 19-8
ex1908
#include <stdio.h>
int main()
{
char alphabet[26];
int x;
char *pa;
pa = alphabet; /* initialize pointer */
/* fill the array */
for(x=0;x<26;x++)
{
*pa++=x+'A';
}
pa = alphabet; /* re-initialize pointer */
/* output the array */
for(x=0;x<26;x++)
{
putchar(*pa);
pa++;
}
putchar('\n');
return(0);
}Output
ABCDEFGHIJKLMNOPQRSTUVWXYZ
Notes
* In the *pa++ operation, the ++ operator binds more tightly than the * operator. Both operators have the same level in the Sacred Order of Precedence, but the operators are read right-to-left. Even so, because the ++ is postfixed, the address at pa is used first (before it's incremented). So * reads the value at that address, then the address is incremented. If it worked the other way, the output would show only letters A through Y.
Copyright © 1997-2025 by QPBC.
All rights reserved
