0

How to use variable in array initialisation? (In c)

Like, Instead of a[100], How i can take the value and put it in the array, n = input Like, a[n]

12th Oct 2024, 7:43 AM
Debojit Santra
Debojit Santra - avatar
4 Answers
+ 4
Debojit Santra in Microsoft C, which supports an older standard (C89/C90), you must use malloc/calloc with free to dynamically manage heap memory for the array. Sololearn uses gcc which supports standard C11 that allows compilers to implement Variable Length Arrays (VLAs). So here you may simply declare it: int a[n];
12th Oct 2024, 1:10 PM
Brian
Brian - avatar
+ 1
Mention the relevant programming language
12th Oct 2024, 8:55 AM
Lisa
Lisa - avatar
12th Oct 2024, 11:15 AM
Lisa
Lisa - avatar
0
In c
12th Oct 2024, 11:08 AM
Debojit Santra
Debojit Santra - avatar