Are the following array declarations valid, if not why?: "i'm confused!"
const int SIZE=4;
void main()
{
int a= {0,2,4,6};
static int b={0,2,4,6,8};
int x[SIZE-5];
int d[SIZE*2];
. . .
. . .
}

>>static int b={0,2,4,6,8};
SIZE = 4; b has 5 elements - not good

>>int x[SIZE-5];
SIZE-5 = -1. You cannot declare an array with negative dimention.

Also, int main () , not void main ().
And, for defining the size of an array, I prefer #define SIZE X instead const int SIZE=X,

#define is old C style syntax, in C++ const is preferred.

Are the following array declarations valid, if not why?: "i'm confused!"
const int SIZE=4;
void main()
{
int a= {0,2,4,6}; ---------------(1)
static int b={0,2,4,6,8};
int x[SIZE-5];
int d[SIZE*2];
. . .
. . .
}

You can re-write the statement (1) as follows:
int a[] = {0,2,4,6};
void main()
{

...

}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.