Deleting and redeclaring char

char data[40];//Declared char
delete data;
char data[50];

error: conflicting declaration 'char data[50]'
error: data has a previous declaration as 'char data [40]'
Last edited on
What is your question?
You may only use delete on a value supplied by new.

Here, that is not the case.
You seem to have misunderstood what the delete keyword does. It invokes the destructor for the object pointed to by a pointer, and then frees up dynamically allocated memory pointed to by that pointer. You should only ever use it with dynamically allocated memory.

It doesn't magically remove the variable altogether from your code. The variable - a pointer - still exists, and you can't just re-declare it.
thankyou, Actually I was trying to create an array as per requirement in runtime that would replace an existing one to save space. I get it now.
Topic archived. No new replies allowed.