+ 1
Why can't we store the address of variable in a normal variable wich is not a pointer? Why the pointer is preferred to
6 Respuestas
+ 1
Not just access the content, but also make changes to the content. So you are actually changing the value of a variable using another variable.
+ 2
Do you mean like this?
https://code.sololearn.com/clJ0mP9S64se/?ref=app
+ 1
Just like you can't store an integer in a string, you can't store a pointer in an integer. Even though the value in a pointer is an integer, but the difference is that a pointer allows you to access the memory and make changes directly to it, but an int only allows you store and access the memory.
For example, in the following program let's consider that the memory address of x is 123456
int x = 10;
int* y = &x;
int z = 123456;
So in the above program, both y and z store the memory address of x. But you can make changes in the value of x using y but not z.
This works and changes the value of x to 100
*y = 100;
But this doesn't work
*z = 123456
+ 1
Thanks for the reply
So to store address we prefer pointer which is unique and only can be used to store the address data type and access the contents using dereference operator.
0
Yeah I got it now
0
Yes. I saw the difference too for address the the data is in hexadecimal form for int it is in integer form thank you for responding