New to C++ and trying to understand use of * and &.
I think I understand that &*var is useful if I want to have a reference variable to a pointer as a function argument, or just as a reference variable to a pointer in general. What about if the & and * are flipped?
Is *& redundant in C++?
Here's some code:
#include <iostream>
using namespace std;
int main(){
// example 1
int num = 10;
cout << *# // exact same as num?
// example 2
struct person
{
string name;
int age;
};
person me[3];
me[0].name = "my name";
me[0].age = 321;
cout << (*&me[0]).name << endl; // exact same as me[0].name?
return 0;
}
Is the use of
*&varin the twocout's redundant because&varis an address and the*that comes before&varmeans to look at the variable the address is pointing to?If it is not redundant, what is the use of
*&varin C++?