Address and Value
Completed
Read an integer x. Make int *p = &x;, change the value through *p to *p * 2, then print x and *p.
Input
One integer.
Output
Two lines.
Example
Input
21
Output
42 42
Editor
C
Hints
&x is the address of x; *p is the value stored at that address.
Solution explanation
A pointer holds an address. Writing through *p changes the variable it points to.
Show solution
#include <stdio.h>
int main() {
int x;
scanf("%d", &x);
int *p = &x;
*p = *p * 2;
printf("%d\n%d\n", x, *p);
return 0;
}