I am trying to fill an array with random integer values like below.
int main(){
srand(time(0)); // initialize rand
int arraySize = 0;
//read in a value and store in arraySize
printf("Enter your array size: ");
scanf("%d", &arraySize);
//declare array of arratSize
int array[arraySize];
for(int i = 0; i < arraySize; i++){
array[i] = rand();
printf("%d ", &array[i]);
}
printf("\n");
return 0;
}
The code generates different numbers every time but they are all in increments of 4 increasing.
for example if 5 was entered for the array size the out put was: -271225040 -271225036 -271225032 -271225028 -271225024
Whats going on?
Aucun commentaire:
Enregistrer un commentaire