Question.1
A developer creates a Sensor object using malloc in a C++ project:
Sensor* s = (Sensor*)malloc(sizeof(Sensor)); s->init();
Another developer uses new:
Sensor* s = new Sensor();
What critical difference does new provide over malloc?
new
malloc
Select Answer
new allocates memory and calls the constructor
new allocates on the stack; malloc on the heap
if memory allocation failed, new returns nullptr while malloc throws an error
nullptr
No difference