Dynamic Matrix

Hard Pointers PRO
🔒 Login to Unlock

Problem Statement

Write a C++ program allocating a dynamic 2×2 matrix using pointers-to-pointers (`int **`), populating values, and deallocating memory properly.

Input Format

4 integers representing a 2x2 matrix.

Output Format

Print 2x2 matrix elements row by row.

Constraints

-100 <= Elements <= 100

Sample Input

1 2
3 4

Sample Output

1 2
3 4

Explanation

Manages dynamic 2D arrays using an array of pointer rows.

Starter Code

#include <iostream>

int main() {
    int **mat = new int*[2];
    for (int i = 0; i < 2; i++) mat[i] = new int[2];

    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            std::cin >> mat[i][j];
        }
    }

    // Write your code here to print matrix and free memory
    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