Solution for Exercise 18-10
ex1810
#include <stdio.h> int main() { char lead; char *sidekick; lead = 'A'; /* initialize char variable */ sidekick = &lead; /* initialize pointer IMPORTANT! */ printf("About variable 'lead':\n"); printf("Size\t\t%zd\n",sizeof(lead)); printf("Contents\t%c\n",lead); printf("Location\t%p\n",&lead); printf("About variable 'sidekick':\n"); printf("Contents\t%p\n",sidekick); printf("Peek value\t%c\n",*sidekick); return(0); }
Output
About variable 'lead':
Size 1
Contents A
Location 0x7ffee2adda2b
About variable 'sidekick':
Contents 0x7ffee2adda2b
Peek value A
Notes
* 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