Question: I've made a shuffling type program that obtains from `cases[];` and arranges them in a random order.

```
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void deal(void);

int cases[22] =      {1,2,3,4,5,6,8,10,15,20,25,35,50,65,85,100,105,135,165,200,250};

int main()
{

   srand(time(NULL));

  int a = 0;

  deal();

  for(a = 0 ; a < 22 ; a++)
  printf("%d \n", cases[a]);

 return 0;
}

void deal(void){
 int loop;
 int temp;
 int x;
 int y;

 for(loop = 0; loop < 50; loop++){

    x = rand() % 22;
    y = rand() % 22;

    temp = cases[x];
    cases[x] = cases[y];
    cases[y] = temp;
 }
}

```

However when I run the code it comes with a randomly placed `0`. Where is it from and why is it there?

Example output:

```
6
15
0 //I don't want that
20
5
50
10
3
165
65
135
105
8
1
200
25
100
85
2
250
4

```

Answer: 
You declare your array as:

```
int cases[22] = {1,2,3,4,5,6,8,10,15,20,25,35,50,65,85,100,105,135,165,200,250};

```

Without you know it, there is actually only 21 elements in that array. Thus, in C standard compilers, the non-initialized value would be set as zero. To correct it, add one more element to the array.

```
int cases[22] = {1,2,3,4,5,6,8,10,15,20,25,35,50,65,85,100,105,135,165,200,250, 500}; // add 500

```

And things will be okay.

Anyway, for this kind of initialization, I recommend you to put the elements in multiple lines (say, every 10 elements):

```
int cases[22] = {1,  2,  3,  4,  5,  6,  8,  10,  15, 20,
                 25, 35, 50, 65, 85, 100,105,135,165,200,
                 250, 500}; // add 500

```

And put in nice format to avoid such error.
You have the wrong number of elements in the array. C is a bit stupid, because it is designed so that a compiler can only detect if there is too many elements in an array, but never if there is too few.

To ensure the exact amount of elements, you can declare arrays like this:

```
#define ARRAY_ITEMS(arr) (sizeof(arr) / sizeof(*arr))
#define CASES_ITEMS 22

int cases[] = {1,2,3,4,5,6,8,10,15,20,25,35,50,65,85,100,105,135,165,200,250};

_Static_assert(ARRAY_ITEMS(cases) == CASES_ITEMS, "Wrong array size: cases");

```