#include
void ConstTesting()
{
char* const ptr1 = "Good"; //address is constant
char* s = "sundar";
ptr1 = s; //will be in an error because address is constant
int m = 10;
int const *ptr2 = &m; //content is constant
*ptr2 = *ptr2 + 2; //the content is constant so this will gives error
const char* const cp = "xyz"; //Both address and content is constant
cp = s; //address is constant so this will gives me error
strcpy(cp,"sundar"); //content is constant so this will also gives error
}
int main(int argc, char* argv[])
{
ConstTesting();
return 0;
}
No comments:
Post a Comment