0

Int a[n] Is this correct for declearing an array?

after this we can initialize n=5 so then int a[5] is this correct?

12th Nov 2019, 3:06 PM
Arjun T Raju
Arjun T Raju - avatar
4 Answers
+ 4
Correct. But you need define and initialize 'n' variable before using that in as a[n]. int n=5; int a[n]; is correct. but int a[n], n=5; is not correct in c..
12th Nov 2019, 3:21 PM
Jayakrishna 🇼🇳
+ 3
No....because Array size needs to be known at compile time cause it allcates memory statically... So it should be a constant... Like a[10].... When u write a[n].. That n has a garbage value at compile time so it's wrong way cause it allocates array of size n which has garbage value at compile time...cause u are giving value to n later ie at runtime
12th Nov 2019, 5:25 PM
Saurabh B
Saurabh B - avatar
0
please get me the answer with correct way and with details
12th Nov 2019, 3:07 PM
Arjun T Raju
Arjun T Raju - avatar