I had a question about pointer-initializations. C++ compilers would not allow a const object to be modified or assigned to an identifier through which it could possibly be modified. Which ones of the pointer-initializations below are not valid and why?
const int num = 5;
int* ptrInt1 = #
const int* ptrInt2 = #
int* const ptrInt3 = #
The type of variable num is const int, not just int. So any pointer that doesn't point to a const int type would not be valid, in your example ptrInt1 and ptrInt3.
There is another possibility you've not mentioned but that also works:
constint* const ptrInt4 = #
Here ptrInt4 is a pointer to a type const int variable and it is a const pointer i.e it cannot point to anything else