Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting a char array

Tags:

People also ask

How do you clear a char array in C++?

Use the memset Function to Clear Char Array in Ch> header file. memset takes three arguments - the first is the void pointer to the memory region, the second argument is the constant byte value, and the last one denotes the number of bytes to be filled at the given memory address.

When to use delete [] or delete?

delete is used for one single pointer and delete[] is used for deleting an array through a pointer.

How do you clear a char array in Java?

We can use \u0000 value to create an empty char in Java. The Java compiler uses this value to set as char initial default value.


This question is related to this one. Given this code:

char *p = new char[200]; delete[] p; 

what would happen if you set p[100] = '\0' before deleting p?

I had some code where I got a debug error when I tried to delete a not null-terminated char array, something about deleting heap memory that's not assigned. It seemed to delete memory out of the array's bounds.