Solution for Exercise 19-8
ex1908
#include <stdio.h> int main() { char alphabet[27]; int x; char *pa; pa = alphabet; /* initialize pointer */ /* Fill array */ for(x=0;x<26;x++) { *pa++=x+'A'; } pa = alphabet; /* Display array */ for(x=0;x<26;x++) { putchar(*pa); pa++; } putchar('\n'); return(0); }
Notes
* In the *pa++
operation, the ++
actually binds more tightly than the *
. Both the ++
and *
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, then the display part of the code would show only letters A
through Y
.
Copyright © 1997-2024 by QPBC.
All rights reserved