+ 1
If malloc returns void * then what does the new operater returns when it encounters a failure ?
Also please tell me if you could describe how the variable will react with the operations and how can I detect that a failure has occurred ?
3 Respuestas
+ 5
If something goes wrong, it will return a null pointer:
int *p;
if((p = (int*)malloc(25*sizeof(int)) == NULL) {
// something went wrong
}
+ 3
the new operator indicates failure by throwing an exception of type "std::bad_alloc" unless “nothrow” is used, in which case it returns a nullptr :
https://code.sololearn.com/c3aw8gUs5i5w/#cpp
0
Thanks for your help