Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Comments on How to declare variable-length arrays correctly?
Post
How to declare variable-length arrays correctly?
+8
−0
This is meant as a FAQ Q&A regarding variable-length arrays (VLA). The two bugs described below are surprisingly common.
I'm trying to use the variable-length arrays feature of C99 (and newer) but I'm facing problems with it.
-
Whenever I write a program like this, I get strange crashes and unexpected behavior:
int size; int array[size]; scanf("%d", &size);
-
Similarly, I also get crashes and strange behavior when I do this:
int size = 1000000; ... int array[size];
1 comment thread