matrix dynamic memory c++

#include <iostream>

// Function to dynamically allocate memory for a matrix
int allocateMatrix(int rows, int cols) {
    int matrix = new int*[rows];
    for (int i = 0; i < rows; ++i) {
        matrix[i] = new int[cols];
    }
    return matrix;
}

// Function to initialize a matrix with values
void initializeMatrix(int matrix, int rows, int cols) {
    for (int i = 0; i < rows; ++i) {
        for (int j = 0; j < cols; ++j) {
            // Replace this line with your own logic for matrix initialization
            matrix[i][j] = i * cols + j + 1;
        }
    }
}

// Function to display the contents of a matrix
void displayMatrix(int matrix, int rows, int cols) {
    for (int i = 0; i < rows; ++i) {
        for (int j = 0; j < cols; ++j) {
            std::cout << matrix[i][j] << " ";
        }
        std::cout << std::endl;
    }
}

// Function to deallocate memory for a matrix
void deallocateMatrix(int matrix, int rows) {
    for (int i = 0; i < rows; ++i) {
        delete[] matrix[i];
    }
    delete[] matrix;
}

int main() {
    // Define matrix dimensions
    int rows = 3;
    int cols = 4;

    // Allocate memory for a matrix
    int myMatrix = allocateMatrix(rows, cols);

    // Initialize the matrix with values
    initializeMatrix(myMatrix, rows, cols);

    // Display the contents of the matrix
    std::cout << "Matrix Contents:" << std::endl;
    displayMatrix(myMatrix, rows, cols);

    // Deallocate memory for the matrix
    deallocateMatrix(myMatrix, rows);

    return 0;
}