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); }
Notes
* The (*pa)++
notation demonstrates the power of the pointer. It illustrates how the same variable can both manipulate a value at a location and potentially change locations as well. (Although in this example the location stored in pa
doesn't change.)
* 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