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.
It's an off by one error: Ferico Samuel's answer is correct

This is a complement:

Instead of hard coding `22` as the number of cases you should write your program like this:

```
// no explicit declaration of the size here. The compiler automatically
// puts the correct size depending on the number of elements that follow.
int cases[] =      {1,2,3,4,5,6,8,10,15,20,25,35,50,65,85,100,105,135,165,200,250};
...
for(a = 0 ; a < sizeof(cases) / sizeof(cases[0]); a++)
...

```

`sizeof(cases)` is the size of your `cases` array in bytes
`sizeof(cases[0])` is the size of one element of the `cases`array
thus `sizeof(cases) / sizeof(cases[0])`is the number of elements of the array.

This way you can add more elements to the `cases` array without the need to change the array size elsewhere in your program.