+ 8
What is the difference between dereference and pointers?
16 ответов
+ 12
A pointer is a type of variable that can be used to hold a memory address, usually of other variables. It can point to the address of any type of variable, which must be specified during its declaration. The syntax for declaring pointers requires a '*' after the type.
Eg : int a=5; int* ptr = &a;
// here, & is the address of
// operator, used to get the address of a.
Now, if you operate on a pointer directly, you get the underlying address, instead of the value at that address. But you can also use a pointer to get the value. That is achieved by the dereference/indirection operator *. Eg : cout<<*ptr; // prints 5.
The difference is simple. If there is a type on the left of the *, then it is a pointer declaration, otherwise it a pointer dereference operation, provided the operand on the right is a pointer.
+ 6
Hi there,
Reference is just a alias name for some variable they are technically same variables but with different name
Example :
int a = 10;
int &b = a ;
{Value of b will be = 10}
Changing "b" will cause "a" to change
A pointer is a variable that stores memory address of some other variable
STORAGE of variables in memory is like following
[ Memory Address ]: [ Value ]
Example
int a = 1;
Suppose it is stored as follows in memory
[ 1500 ]:[1]
It tells that at address 1500 the value is 1( it will be in hexadecimal in reality , for sake of simplicity I write it normally )
The pointer stores the memory address of the variable
So
int *p = &a ;
{Value of p will be = 1500}
And
{Value of *p will be 10}
"*p" represents the value stored at the adress
To summarise
int a = 10;
int &b = a;
int *p = &a ;
b equals 10 and
p equals some memory address in hexadecimal
And *p is also 10
I hope this will help you. : )
+ 4
Opps! I overlooked it....😋
+ 3
HonFu yeh sorry for that
+ 2
There is a difference?
My interpretation has been:
There is an action called dereference, which means accessing a value indirectly via its address using a pointer.
And the pointer would be the tool to do the referencing.
+ 2
Anurag Kumar, I didn't know your syntax int b = &a;, so I checked it and got an error.
Did you mean int &b = a;?
+ 2
The * is a pointer, the & is a reference. The difference between the two is that a pointer is an area of memory that must be dereferenced, eg. by means of the -> operator in order to be "seen" as a class instance. A reference is instead an "alias", just an alternative name for the same class instance.
https://crbtech.in/java-training/top-best-java-training-institutes-in-pune
+ 2
Hi meenal, so what's the 'data type' of the area in memory?
+ 1
One has to careful when using pointer... It does not take into consideration the 'data type' of the content of the address....
+ 1
One has to careful when using pointer... It does not take into consideration the 'data type' of the content of the address.... The result would be u predictable. Think twice when you're dealing with * or &
+ 1
Pointers simply point to an address in memory. A dereference shows you the value held within that address. Hope that answers your question.👌
+ 1
what the deffrent betewin dereferencing and pointer?
0
Hola
0
what the deffrent betewin dereferencing and pointer deply?
0
what does it mean & in c++?
0
Differences between & and *?