C++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

C++

What is the difference between ampersand (&) and asterix (*) in pointers?

6th Apr 2019, 4:34 AM
Svojas Pitale
Svojas Pitale - avatar
1 Answer
+ 4
When working with pointers in general, the & symbol followed by the variable name (ex. &x) returns the address (location) of that pointer, generally as a hexadecimal value such as 0x23fe48. The * on the other hand returns the actual value being pointed at by that pointer, so if the value at the location of a pointer were 5, running the line cout << *x; will print out 5.
6th Apr 2019, 4:41 AM
Faisal
Faisal - avatar