Probably it use swap the pointer to address's vaue to achieve the swapping.In other words, swap thier value. I want to know could we do it in other way, swap the pointer to address instead of its value ?
For example , before swap
&x //address of x =FFAA00 and its value=42
&y /address of y =BBCC00a and its value=17
after swap
&x //address of x =BBCC00 and its new value=17
&y /address of y =FFAA00 and its new value=42
Or I need to think about to do that using pointer of pointer
Thanks for your reply. If possible, could I know what is that pointer declaration meaning of
int *ptr = (int *) 0x1234; ?
what is (int*) stand for that always seen in tutorial articles on internet?
Rwniceing
Zoppo
Well, you know pointers are nothing else than some kind of integer values holding the address of a variable of a given type. If an address is assigned to a pointer (i.o.w. changing the value of the pointer) the pointer type needs to be the same, so you can't i.e. simply assign a pointer to float to a pointer to int.
In your sample the new value 0x1234 is of type int, so it needs to be type-casted to a pointer to int because the compiler doesn't allows assinging anything else than a pointer.
thanks for your, Zoppo, I will digest it with cout<< <<endl testing with that.
My goal of this topic is knowing more actual concept for pointer and basic C++ with its syntax
Open in new window
ozo, you know what I'm asking ?