Initialize to 2D array element 0.0C language

Asked 2 years ago, Updated 2 years ago, 65 views

When you declare a two-dimensional array dynamic assignment and enter the number of rows and columns, you want all the elements in the array to be initialized to 0.0, but I'm not sure what's wrong.

void creatematrix(int row, int col)
{
    cin >> row >> col;
    double** data = new double* [row];

    for (int i = 0; i < row; i++)
    {
        data[i] = new double[col];
    }

    for (int i = 0; i < row; i++)
        for (int j = 0; j < col; j++)
        {
            data[i][j] = { 0.0 };
        }

If you enter cout and delete below, it will not be executed. I would really appreciate it if you could tell me where it went wrong :)

array allocation initialization c c++

2022-09-20 13:32

1 Answers

data[i][j] = { 0.0 }; ==> data[i][j] = 0.0;


2022-09-20 13:32

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.