Solution for Exercise 18-12
ex1812
#include <stdio.h> int main() { int v = 1812; int *pv = &v; printf("The value if 'v' is %d\n",*pv); return(0); }
Output
The value if 'v' is 1812
Notes
* The int variable v
is declared and assigned a value at Line 5. You could also declare the variable and assign its value separately.
* The int pointer variable pv
is declared at Line 6, plus it's immediately initialized to the address of int variable v
. 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 v
(at Line 5) by using the pointer *pv
.
Copyright © 1997-2024 by QPBC.
All rights reserved