c ++ assigning values to an array globally

when I declared a global array

int color[5005]

I assigned all its values -1 outside the main function

for (int i = 0; i < 5005; i++) color[i] = -1;

It gave me error.
But when i did this inside the main function it didn’t.

I am new to c++, please help.

#i guess this is what u wanted

using namespace std;

int main()
int color[5005];

for (int i = 0; i < 5005; i++)
color[i] = -1;

return 0;

this will print -1
5005 times.

if u type
int color[5005]={-1};
it will assign -1 to only color[0];

@mathecodician You can declare global/static variables outside a function body, but you can’t put statements outside a function body.