A
A
Anonymous859662020-10-29 10:09:26
C++ / C#
Anonymous85966, 2020-10-29 10:09:26

How to create an array with the number of elements equal to the number entered?

int s=0;
scanf_s("%d", &s);
int arr[s];
This code throws an error, because s must be declared as const. But if I declare s as const, I will not be able to change its value when entering a number using scanf_s. What construct should be used to
store a number in a variable when input and create an array with a size equal to this variable?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ronald McDonald, 2020-10-29
@Anonymous85966

You need to create a dynamic array.
It wobbles once or twice.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question