Dynamic Arrays

Let's revise the creation of dynamic arrays.

We'll cover the following

Problem

Write a program that receives the size of an array and then allocates memory for it dynamically. It also needs to receive numbers into this array and print them on screen. The program should use C and C++ styles to accomplish these tasks.

Sample input

In the example given below, the very first input, 2, is the array size followed by two integers for the C style allocation. Similarly, the fourth input, 3, is the array size followed by three integers for the C++ style allocation. You have to provide inputs under the “Enter the input below” tab and then press the “Run” button.

2

100

200

3

1

2

3

Coding solution

Here is a solution to the above problem.

Get hands-on with 1200+ tech skills courses.