ProgrammingHard

A loop reads n numbers and stores them in int a[n] as a VLA of size up to 10^6 inside main. What is the main risk?

  1. A. A VLA cannot hold integers
  2. B. A VLA is slower because it is sorted automatically
  3. C. The VLA is zeroed, which takes too long
  4. D. A large VLA lives on the stack, which can overflow, so heap allocation is safer for big sizes

Correct answer: D. A large VLA lives on the stack, which can overflow, so heap allocation is safer for big sizes

Big automatic arrays use the stack, which is limited. malloc or a global array is safer for large sizes.

More C Programming questions

Exams that ask this topic