NVIDIA Interview Question
Software Engineer / DevelopersCountry: United States
Interview Type: Phone Interview
Easy way to remember this, since it is somewhat confusing at times:
get the type near to the keyword const
1) const char *ptr ==> const char ==> the character value (to which this pointer points) is constant.
2) char * const ptr ===> const * ==> the pointer is constant and can point to only one memory when it was initialized.
Read right to left.
const char * p = "p is a pointer to char which is constant"
char * const p = "p is a constant pointer to a char"
const char *p, char * const p
first is constant character pointer, the value pointed by p is constant.
second one is a constant pointer to character, where the value of p (address) is constant.
const char pointer: const char *
- axa May 09, 2012The chars the pointer points to cannot be modified.
const pointer to char: char * const
The address the pointer points to cannot be modified.