0
C++ pointer
suppose I have: int a=100; int *ptr; ptr = &a; // set ptr to point' to the address in //memory occupied by int a. cout<<&ptr;<<endl; cout<<ptr<<endl; Do you know that statements cout<<&ptr. and. cout<<ptr respectively, both will give us the same result or output? Both line Will output the memory address occupied by integer a variable that the pointer ptr is currently pointing to?
5 Antworten
+ 2
No they won't
"&ptr" will be the memory location of the pointer itself.
"ptr" will be the content of the variable of pointer type, this means it will contain the address of "a" in this case.
0
#include <iostream>
using namespace std;
int main() {
int a =10;
int *ptr;
ptr = &a;
cout<<&a<<endl;
cout<<&ptr<<endl;
cout<<ptr<<endl;
return 0;
}
Please check this one.
Cout<<&a and cout<<p: both will return the memory address which is occupied by integer variable a or in the other word it return the location of memory address which is bring pointed by pointer to integer variable *ptr (it is set to point' to memory address location occupied by integer variable a which is store int value 100 , while cout<<&ptr itself will return the memory address occupied by int *ptr (not memory is pointed to).
0
Do you agree with my opinion or statement friends?
0
Oliver Pasaribu what you said in comments is correct