Solution for Exercise 18-12
ex1812
#include <stdio.h> int main() { int i = 1814; int *pi = &i; printf("The value of 'i' is %d.\n",*pi); return(0); }
Notes
* The int variable i
is declared at Line 5.
* The int pointer variable pi
is declared at Line 6, plus it's immediately initialized to the address of int variable i
. This approach is different from using two separate statements because the *
is used to declare a pointer variable, but you don't use the *
when initializing a pointer variable to an address. Here are the two statements you could otherwise use:
* Line 8 displays the value assigned to variable i
(at Line 5) by referring to the pointer *pi
.
Copyright © 1997-2024 by QPBC.
All rights reserved