What did I point at? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What did I point at?

https://code.sololearn.com/cTicnDY6GzhE/?ref=app Can someone explain what I pointed at? I was playing with pointers to better understand how they work. Now I'm confused.

6th Jul 2017, 1:30 PM
Vote4Pedro
Vote4Pedro - avatar
3 Answers
+ 1
I knew I was pointing to something other than the variable a, the point of writing the code was to see what would happen if i send it to something other than a variable. I'm aware of the difference between *wut and wut. What I wanted to know is what the info the pointer returned was. Shouda worded my question better. Thanks for the help tho!
6th Jul 2017, 7:29 PM
Vote4Pedro
Vote4Pedro - avatar
0
OK.. There is a big problem: You don't know the difference between 'wur' and '*wur'. int a=4; // classic variable int *ptr ; // pointer on an int Now how can 'ptr' point on 'a' ? ONE way : ptr=&a; a pointer store an adress. a's adress is &a (&a==0x45cg4i or something like that) Now that 'ptr' point on 'a', you have : ptr==&a==0x45cg4i; // true *ptr==*&a==a==4; // true BUT ptr!=a and *ptr!=&a.
6th Jul 2017, 4:12 PM
Jojo
- 1
A pointer can only have an adress as value. Just like a char can only have a char. int *ptr; int u=2; ptr=56; // error ptr=u; // error
6th Jul 2017, 7:51 PM
Jojo