View Full Version : difference between "const int i" and "int const i"
aryasir
08-30-2005, 06:59 PM
Is there a difference between the following two lines:
const int i = 0;
int const i = 0;
apparently, I was told they are different, so I wanted to know the difference.
donBerto
08-30-2005, 09:35 PM
hehe one of my professors taught us this. too bad for me, I wasn't paying attention. thank god for google.
check out the following week. your question can be answered by, "More Geeky Stuff" at the bottom.
http://www.phim.unibe.ch/comp_doc/c_manual...NTAX/const.html (http://www.phim.unibe.ch/comp_doc/c_manual/C/SYNTAX/const.html)
regards,
:yes:
bladder
08-30-2005, 11:21 PM
They're exactly the same, the difference with the positioning of "const" comes into play when you use pointers.
const int* is a constant pointer to integer data, that means you cant change the pointer itself to point to something else.
int* const is a pointer to constant integer data, which means you can change the pointer, but you can't change the data it points to.
Arjen
08-31-2005, 12:39 AM
const int* is a constant pointer to integer data, that means you cant change the pointer itself to point to something else.
int* const is a pointer to constant integer data, which means you can change the pointer, but you can't change the data it points to.
20554
That would be the other way around.
const int* -> a (variable) pointer to constant integer data
int* const -> a constant pointer to integer data
The trick is reading from right to left.
bladder
08-31-2005, 01:07 AM
woops, right my bad :wallbash:
vBulletin, Copyright ©2000-2009, Jelsoft Enterprises Ltd.