+ 1

What is different between "&" and "*" to declare a pointer?

14th Jan 2017, 6:09 AM
miladmp
miladmp - avatar
4 Respostas
+ 11
& is the address-of operator. * is the point-to operator. int *r = 0; int s = 0; // declaring a pointer and a variable. r = &s; // assign address of s to r. cout << *r; // tells program to print whatever the address stored in r points to.
14th Jan 2017, 6:16 AM
Hatsy Rei
Hatsy Rei - avatar
+ 8
In int &p; The "&" here isn't used as a operator. It denotes a reference instead of a pointer to an object. I suggest you to take a look at the differences between a pointer and a reference. https://www.quora.com/What-are-the-differences-between-references-and-pointers
14th Jan 2017, 6:38 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
what is: int &p;
14th Jan 2017, 6:29 AM
miladmp
miladmp - avatar
+ 1
tnx
14th Jan 2017, 8:19 AM
miladmp
miladmp - avatar