mardi 6 octobre 2020

about rand function....(language c) [closed]

I'm making quicksort. when I make some random integer array, it doesn't work...

int* createArray() {
    int* newarr = (int*)malloc(sizeof(int) * n);
    int randnum;
    for (int i = 0; i < n; i++) {
        randnum = ((((long)rand() << 15) | rand()) % n) + 1;
        newarr[i] = randnum;
    }
    return newarr;
}

randnum = ((((long)rand() << 15) | rand()) % n) + 1;

this code occur error..

error code: 0xC0000005 when I print randnum, it works. However I don't wanna print.




Aucun commentaire:

Enregistrer un commentaire