Is this allowed in C Language as given below:
int a=2, b=3;
int arr[a+b];
Is this a valid C statement?
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.
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;
}
int a=2,b=3; int arr[a+b];?arris a pointer or array object declared.. somewhere. And even then, it's pointless as it doesn't actually do anything.#define A = 2 #define B = 3 int arr[A+B];