Dynamic Arrays of Objects

Medium Dynamic Memory & Smart Pointers
Solve in Playground →

Problem Statement

Dynamically allocate an array of 3 `Point` objects on the heap using `new[]`. A `Point` has an integer `x` and `y`. Read 6 integers from input to populate the array. Print them sequentially, then use `delete[]` to free the array.

Input Format

6 space-separated integers.

Output Format

Print each point formatted as 'P: [x], [y]' on a new line.

Constraints

Must use new[] and delete[].

Sample Input

1 2 3 4 5 6

Sample Output

P: 1, 2
P: 3, 4
P: 5, 6

Explanation

To allocate contiguous arrays of objects on the heap, you must use `new[]`, and to avoid partial memory leaks, you must clean them up specifically with `delete[]`.

Starter Code

#include <iostream>

class Point {
public:
    int x, y;
};

int main() {
    // Allocate dynamic array of 3 Points, read data, print, and clean up
    return 0;
}

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used