Unable to free const pointers in C
- by lego69
How can I free a const char*? I allocated new memory using malloc, and when I'm trying to free it I always receive the error "incompatible pointer type"
The code that causes this is something like:
char* name="Arnold";
const char* str=(const char*)malloc(strlen(name)+1);
free(str); // error here