Question: c++ When we dynamically allocate an array, we often do so because we don't know the size of the array at compile time. We might
When we dynamically allocate an array, we often do so because we don't know the size of the array at compile time. We might write code such as size_t num-get_size(): //get_size returns number of elements needed int ptr = new int[num): for (int 'k - ptr:k!- ptr + num; ++k) /* process the array / to figure out the size of the array and then allocate and process the array. An interesting question is: What happens if get_size returns 0? This code will not compile This code works does not work. The language specifies that a call to new to create an array of size zero is illegal. It is illegal and we could not create an array variable of size 0 This code yields a run-time error The code works fine. The language specifies that a call to new to create an array of size zero is legal. It is legal even though we could not create an array variable of size 0 none of these
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
