Reputation: 1
Is this allowed in C Language as given below:
int a=2, b=3;
int arr[a+b];
Is this a valid C statement?
Upvotes: 0
Views: 86
Reputation: 224596
An array declare with a size that is not a integer constant expression is called a variable length array. It is allowed in C, although not for arrays with static or thread storage duration.
The 1999 C standard required C implementations to support variable length arrays. The 2011 standard made support optional.
Upvotes: 3
Reputation: 421
You can do something like this:
#include <stdio.h>
#define A 2
#define B 3
int main(){
int a=A, b=B, arra[A+B];
return 0;
}
Upvotes: 1