Jan 25, 2010 at 6:46pm UTC
hi, started to read book Lipman C++ and have first questions about pointers,
here is my code
1 2 3 4 5
int i = 2;
int j = 4;
int const * pi = &i; //const pointer to int type
pi = &j;
i compile this code in VS2008, and it's success, but why, i change the value of pi?
Last edited on Jan 25, 2010 at 6:47pm UTC
Jan 25, 2010 at 6:54pm UTC
thanks alot, is
const int * and int const *
same at all, or have some difference?
Jan 26, 2010 at 11:51am UTC
what about const int const * const const pi;
why compiler doesn't panish?
Jan 26, 2010 at 12:54pm UTC
That type is invalid. Firstly, 'int' is being made const twice. Secondly, there's two const in a row after the asterisk.
'int const * const' or 'const int * const' would be valid, though.
Jan 26, 2010 at 2:42pm UTC
Probably an overly permissive compiler.
test.cpp: In function `int main()':
test.cpp:306: error: duplicate `const'
test.cpp:306: error: duplicate `const'
EDIT: I just tried it with VC++. It doesn't produce an error, but it does produce a warning:
warning C4114: same type qualifier used more than once
warning C4114: same type qualifier used more than once
Last edited on Jan 26, 2010 at 2:44pm UTC