I'm trying to create a code in using C that creates an array, swaps all the numbers in the array, and tests which sort method is faster, but for some reason it stops swapping after exactly 32768 numbers, I'm pretty new to coding and I don't know what i'm doing wrong
void swap(int *a, int *b){
int temp;
temp=*a;
*a=*b;
*b=temp;
}
for(k=0;k<nswap;k++){
r1=rand()%max;
r2=rand()%max;
swap(&vet[r1],&vet[r2]);
}
This is just a part of the code, every variable has been declared correctly.
Edit: The array "vet" is initialized as vet[max] where max is a "#define max 35000"
by "stop" i mean that r1 and r2 don't swap numbers that are higher then 32768.
"k" is just a variable i use in loops. "k" does get higher then 2^15 but r1 and r2 don't
here's a reproducible example:
#include <stdio.h>
#include <stdlib.h>
#define max 35000
#define nswap 35000
void swap(int *a, int *b){
int temp;
temp=*a;
*a=*b;
*b=temp;
}
int main(int argc, char *argv[]) {
srand(time(NULL));
int vet[max];
int vettemp[max];
int k, r1, r2, temp;
for(k=0;k<max;k++){
vet[k]=k+1;
}
for(k=0;k<nswap;k++){
r1=rand()%max;
r2=rand()%max;
swap(&vet[r1],&vet[r2]);
}
for(k=0;k<max;k++){
printf("%d ", vet[k]);
}
return 0;
This is where my problem comes
I've tried to eliminate some useless declaration but it didn't work