I'm scratching my head over this silly one: Why does method 1 give me an error, and method 2 compile just fine? (don't mind the warning though( 1. http://ideone.com/c3aju 2. http://ideone.com/MuEpG
Btw, in method 2. if I switch the char* and the const keywords around, it gives me an error.
It's the difference between making the variable constant and the pointer constant. const char* makes the pointer constant, meaning you won't be able to modify its contents. char* const, which is what the typedefed version also boils down to, makes the variable constant, meaning you can't reassign to it.
it's all clear now :-D
Maybe that K&R book can help me understand how the const keyword really works in C.
Ah, K&R Page 40 verse 5, and Lo!: "The qualifier const can be applied to the declaration of any variable to specify that its value will not be changed. For an array, the const qualifier says that the elements will not be altered."
However, if I take method 1 and initialize it on the same line, it doesn't give me a compile error O.o http://ideone.com/nfkA8
The typedef version is expected. const protects from *reassignment*. The non-typedef one is an order thing I think (const char* vs char* const).
Can i get a pdf format of that K & R BOOK ???????
isn't it available for free as a pdf format file ?????
Nope :(
Join our real-time social learning platform and learn together with your friends!