+ 4

Can I assign a value to a pointer?

21st Oct 2019, 12:14 PM
Abdelhaq
Abdelhaq - avatar
3 Answers
+ 7
When you initialize the value, you store a value in that pointer itself (like if the star wasn't there, yeah, that's a bit confusing). So what you store in there, has to be an address. int n; int *p = &n;
21st Oct 2019, 12:23 PM
HonFu
HonFu - avatar
+ 4
The type of value you assign to a pointer is a memory address. And by using *, you can assign a value to the place the pointer is pointing to, but the value of the pointer itself stays the address of that place.
21st Oct 2019, 12:16 PM
HonFu
HonFu - avatar
+ 1
I can't do this : int *p = 45 ; ?? Because when I want to print the value it is pointing to I use *p
21st Oct 2019, 12:19 PM
Abdelhaq
Abdelhaq - avatar