int*
means a variable which can contain address of a integer
variable. Now address of an integer variable when placed on the right
hand side of the assignment then the left hand side should be int*
otherwise it will give wrong results. That's what is told here.
Where is the pointer?
dp
is a pointer but not an integer pointer that's why the error.
rvalue
- the value that appears in the rhs of assignment operator.
A=B (r-value)
Do you know why we need different pointers? Suppose you have a pointer
variable pointing to a chunk of integers.
BBBBBBB (bytes)
|
pointer(p)
BBBBBBB (bytes)
|
p+1 if pointing to int
BBBBBBB
|
p+1 if ointing to char
Now if we say p++, then where do we move.
Okay if it is pointing to int move( sizeof(int)) 4 bytes , if
character 1 byte. Now say you are allowed to do wrong r-value
assignment. then it will be very problematic. You have to careful
enoough to code it properly.
Now hope you understand the whole picture.
Note:Look it is saying you can not initialize a double *
with an r-value of int*
. What is the r-value of an int *
? it is address of an integer variable. So you are assigning to a double pointer an r-value of int*
not r-value of double*
which is an address of a double
.
FROM MSDN
Every C++ expression is either an lvalue or an rvalue. An lvalue
refers to an object that persists beyond a single expression. You can
think of an lvalue as an object that has a name. All variables,
including nonmodifiable (const) variables, are lvalues. An rvalue is a
temporary value that does not persist beyond the expression that uses
it. To better understand the difference between lvalues and rvalues,
consider the following example:
example
For further example/clarification check this SO question
exact-difference-between-rvalue-and-lvalue