670 B
670 B
Basics
- const char vs char
const char *p: This declares a pointer p that points to a constant character (immutable). It means that the data pointed to by p cannot be modified through p. However, p itself can be changed to point to a different memory location. Sop[0]='H'is invalid as this constant say 'hello' is read only but if it is simplychar *pthenp[0]='H'is a valid operation Wierd Case ifconst char *pis equivalent to 'hello' and we dochar *q=p;andq[0]='H'then it is invalid bcz constant pointed by p is still read only and no matter if another pointer is pointing to it, that constant is still read only.