Solution for Exercise 18-10
ex1810
#include <stdio.h> int main() { char lead; char *sidekick; lead = 'A'; /* initialize char variable */ sidekick = &ead; /* intialize pointer - IMPORTANT! */ printf("About variable 'lead':\n"); printf("Size\t\t%u\n",sizeof(lead)); printf("Contents\t%c\n",lead); printf("Location\t%p\n",&lead); printf("And variable 'sidekick':\n"); printf("Contents\t%p\n",sidekick); printf("Peek value\t%c\n",*sidekick); return(0); }
Notes
* For a Macintosh, or some other Unix variant, change the conversion character used in printf() at Line 12 to %ld
.
* As with the &
operator, the compiler is wise enough to determine when *
prefixes a pointer variable name. So although the *
is also the multiplication operator, it can hug a pointer variable's left side and become a unary pointer operator.
Copyright © 1997-2024 by QPBC.
All rights reserved