1

please advise why below do not work. use VC2017:

long **l;
l = new long [5][7];

it shows error as:

"a value of type "long*[7]" can not be assigned an entity of long**"...

How can I solve it?

1
  • long **l=NULL; l=new long [5][7]; Commented Jan 20, 2019 at 12:47

1 Answer 1

1

You need to declare and init the first array of pointer to long* and then assign to each his own array as:

long** l = new long*[5]; // declare array of pointer of 5 cell
for(int i = 0; i < 5; ++i)
    l[i] = new long[7]; // assign to each cell array with 7 cells

Remember that anything allocated with new is created on the heap and must be de-allocated with delete.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.