memset is not working with pointer to character
What is wrong with the following code? memset is supposed to work with Pointer to the block of memory to fill. But this code displays problem in console saying segmentation fault(core dumped) #include<iostream> #include <cstring> using namespace std; int main(int argc, char** argv) { char* name = "SAMPLE TEXT"; memset(name , '*', 6); cout << name << endl; return 0; } You have tripped over a very old backward-compatibility wart in C++, inherited from C and dating to the days when there was no such thing as const . String literals have type const char [n] , but, unless you tell your compiler you