I am still knew in learning c and i am facing the following problem.
I am trying to initialize and declare an array but it is giving me compilation error.
const int a =2;
int x[a]={2};
I am still knew in learning c and i am facing the following problem.
I am trying to initialize and declare an array but it is giving me compilation error.
const int a =2;
int x[a]={2};
Variable length arrays cannot be initialized.
Assign the values after definition:
const int a = 2;
int x[a];
x[0] = 2;
By using macro you can do that
#include<stdio.h>
#define a 2
int main()
{
int x[a]={2};
//do something with array x
return 0;
}