When trying to check for a value that has been initialized via new(), I can a segmentation fault error.
int main() {
const char* const *matrix = new(char*);
std::cout << matrix[0][0]; // segfault here
return 0;
}
My suggestion is that there should be garbage value, but no segfault.
>Solution :
You allocate new(char*) and assign in to matrix, which makes matrix[0] to not be a segfault because matrix is a valid pointer.
However, matrix[0] is not a valid pointer. It contains a garbage data, so matrix[0][0] tries to get a random memory location, which ends in a segfault.