+ 8

What is the difference between dereference and pointers?

4th Dec 2018, 3:51 PM
Prabhat Kumar Singh
Prabhat Kumar Singh - avatar
16 Respuestas
+ 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.
4th Dec 2018, 4:33 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 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. : )
4th Dec 2018, 4:20 PM
Bad_Bits
Bad_Bits - avatar
+ 4
Opps! I overlooked it....😋
4th Dec 2018, 4:27 PM
Bad_Bits
Bad_Bits - avatar
+ 3
HonFu yeh sorry for that
4th Dec 2018, 4:37 PM
Bad_Bits
Bad_Bits - avatar
+ 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.
4th Dec 2018, 4:22 PM
HonFu
HonFu - avatar
+ 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;?
4th Dec 2018, 4:36 PM
HonFu
HonFu - avatar
+ 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
6th Dec 2018, 11:35 AM
meenal deshpande
+ 2
Hi meenal, so what's the 'data type' of the area in memory?
6th Dec 2018, 2:11 PM
Da2
Da2 - avatar
+ 1
One has to careful when using pointer... It does not take into consideration the 'data type' of the content of the address....
5th Dec 2018, 6:27 AM
Da2
Da2 - avatar
+ 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 &
5th Dec 2018, 6:29 AM
Da2
Da2 - avatar
+ 1
Pointers simply point to an address in memory. A dereference shows you the value held within that address. Hope that answers your question.👌
31st Dec 2018, 6:03 AM
De Leo
+ 1
what the deffrent betewin dereferencing and pointer?
17th Mar 2022, 5:15 PM
megbaru wondimeneh
0
Hola
5th Dec 2018, 10:21 PM
Mirianto Casado
Mirianto Casado - avatar
0
what the deffrent betewin dereferencing and pointer deply?
17th Mar 2022, 5:27 PM
megbaru wondimeneh
0
what does it mean & in c++?
17th Mar 2022, 5:35 PM
megbaru wondimeneh
0
 Differences between & and *?
17th Mar 2022, 5:36 PM
megbaru wondimeneh