0

I know the difference between static (determined by compiler) and dynamic (determined at runtime) allocation. What I don't understand is what happens in the case where we have a situation such as:

int n = 5;
int arr[n];

arr isn't allocated with malloc, so it can't be placed on the heap. However, it also can't be allocated statically, as the program has to run to be able to determine the size of a. So how does arr get allocated?

  • *arr isn’t allocated with malloc* did you use malloc in the code?! – CroCo Apr 21 '18 at 01:11
  • There is a very nice explanation here https://stackoverflow.com/questions/40464927/how-to-dynamically-allocate-an-array-of-integers-in-c – Haris Nadeem Apr 21 '18 at 01:14

1 Answers1

-2

The program doesn't need to run to determine the size of a. Unlike Python or other languages C is compiled before running. The compiler generates the Assembly with the correct alocation for arr with 5 positions.