lundi 12 avril 2021

C++ array declaration on heap? [duplicate]

In C++ we can write:

    int arr[] = {20,3,2,0,-10,-7,7,0,1,22};
//Smal Note: Why int *arr = {20,3,2,0,-10,-7,7,0,1,22}; won't work? I learnt I can replace [] with *

but what if I want to allocated arr on heap in one line?

I tried:

    int arr[] = new int {20,3,2,0,-10,-7,7,0,1,22};

Aucun commentaire:

Enregistrer un commentaire