Answer the question
In order to leave comments, you need to log in
Question about pointers in C++. A variable assigned to a pointer will always go "&Variable" in the code??
Description of the issue:
When declaring a pointer and a variable
int* pPointer = 0;
int x = 1;
pPointer = &x;
cout << &x ;
Answer the question
In order to leave comments, you need to log in
The question is really stupid. Read what the & does in front of the variable name - and you will find the answer to your question there.
And if you answer directly - no, not always.
The & in front of the variable is the address.
The analogy with the address as with the coordinates of a physical object works quite well. You can write down the coordinates on a piece of paper and get a "pointer". If you write down the coordinates of the place where you store the first sheet, then you will get a pointer to a pointer. To simply copy a pointer, you do not need to take its address.
int apple = 1;
int* poinerToApple = &apple;
//просто скопируем указатель
int* poinerToApple2 = poinerToApple;
//ожидаемо оба указывают на одно значение
//assert покажет что условие верно
assert(*PointerToApple == *PointerToApple2);
assert(*PointerToApple == apple);
assert(*PointerToApple2 == apple);
//так получим указатель на указатель
int** poinerToPointerToApple = &poinerToApple;
int** poinerToPointerToApple2 = &poinerToApple2;
//разные указатели имеют разные адреса
assert(poinerToPointerToApple2 != poinerToPointerToApple);
//но они могут указывать на один и тот же указатель
assert(*poinerToPointerToApple2 == *poinerToPointerToApple);
//и по ним мы можем добраться до исходного значения
assert(**poinerToPointerToApple2 == apple);
int x = 5;
cout << x; //напечатает 5
cout << &x; //напечатает что-то типа 0x7fffffffd2e4
How are you going to work with Paypal in Ukraine? We don't officially have it and it's not expected in the near future.
woocommerce has paypal by default. You need to enter your PayPal email, and when paying with PayPal, it will convert from uah to your currency, which is on PayPal
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question