+ 1
Pointer Confusion
Why is this the output of this code: https://code.sololearn.com/cgmfC4j01tb8/#cpp
6 Respuestas
+ 3
By this a++; now a point to some uninitialized location. And giving garbage value...
+ 4
incrementing a pointer, points to the next memory address next to &c. dereferencing it will show some garbage value as Jayakrishna🇮🇳 mentioned .
to understand better
change c to array.
int c [] ={5, 6};
int const *a = c; // do not use & (array)
and check the output.
+ 3
int const* a in your programme is not a constant pointer, it's a pointer to constant data.
you can't change the value, but you can change the object pointer points at.
+ 2
it's like:
const int *p: p is a pointer to int const
int *const p: p is a const pointer to int
that's the difference
+ 1
Dimas ohhh that’s very interesting. Thanks for the info!
0
Thanks Bahha and Jayakrishna :)
And also, does changing memory address of a const pointer not cause an error?