samedi 8 juillet 2017

variable-sized object may not be initialized confusion

The below code is attempting to randomly initialize array z of 0 or 1. I receive the following error message

error: variable-sized object may not be initialized int z[x]= rand()%2;

1 error generated. isn't Z size given as 10?

 int z[10];
     for(int x =0; x <=(sizeof(z) / sizeof(z[0]));x++)
     {
            srand((unsigned)time(NULL));
            int z[x]= rand()%2;
            std ::cout<<z[x];
     }




Aucun commentaire:

Enregistrer un commentaire