Google News
logo
Embedded C - Interview Questions
How will you protect a character pointer by some accidentally modification with the pointer address?
Constant character pointer (const char*) prevents the unnecessary modifications with the pointer address in the string.
 
Example :
///declaration 
const char *str;

//we can reassign the pointer
//string will be declared somewhere in the memory and 
//its address will be assigned to the "str" 
str = "Hello world";

//but, we cannot modify the data 
//that is pointing by the pointer

*str = 'P';//not allowed
Advertisement