Does casting a string as char pointer automatically allocate required memory in C/C++?
So while playing with codes I discovered a new technique of assigning pointer values without allocating memory previously. #################### #include <stdio.h> int main(){ char* name; name =(char*) "String Sample"; return 0; } ####################### The code above works well without explicitly allocating required memory (using mallocs or new keywords) and neither does it throw any error or warning... So does this mean that the (char*) casting of the string automatically allocate the required memory space for the string? And is this method safe to use and recommended for a bigger scale application? This method can be useful when the actual size for allocating a string isn't known... Thanks.... Edit: Fixed a small mistake of casting the lvalue instead the string right hand side.