0

Can we do something like asking the user for the value of a variable, say "size" and then doing later in the code something like:

int array[size];

? If no, why?

1 Answer 1

1

Yes you can. Say you want an array of integers, you can do it like that:

printf("What is the length of the array?\n");
int n = GetInt();
int numbers[n];

for (int i = 0; i < n; i++)
{
    numbers[i] = GetInt();
}
1
  • You can't change the size though if you fill the whole array and want more space.
    – ChrisG
    Commented Jul 10, 2015 at 13:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .