Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

c++ image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions