Question: There is an array x and I want to put its elements in arrays y and z based of some if condition.

```
    int x[10],y[5],z[5];
    for(for x array)
      if(some condition)
         {
             //put in y
        }
       else   {
             //put in z
             }

```

What I am not able to figure out is how to keep track of indexes in array y and z while assigning the elements. Any help/suggestion is appreciated. Thnak you.

Answer: 
For statically defined arrays;

```
int x[10],y[5],z[5];
for(for x array)
  if(some condition)
  {
         //yindex is the index of the y array where you are going to assign the value
         if(yindex < sizeof(y) / sizeof(y[0]))
         {
            y[yindex] = value;
         }
  }

```
you can give like that condition if you will initialize at least one array (y or z) with 0, maybe it will be helpful for you. Example:

```
#include<stdio.h>

int main()
{
    //put values in x array otherwise it will take by default garbage value.
    int i, j, k, x[10], y[5]={0}, z[5]; 
    for(i=0; i<10; i++)
    {
        scanf("%d",&x[i]); //for console input.
    }
    for(i=0, j=0, k=0; i<10; i++)
    {
        if(y[j]==0 && j<5)  //if(y[j]==0)
        {
            //put in y
            y[j]=x[i];
            printf("%d ",y[j]);
            j++;
        } else {
            //put in z
            z[k]=x[i];
            printf("%d ",z[k]);
            k++;
        }
    }
}

```

when you assign size only like `x[10]` without assigning any elements in C then it will store garbage values in array so if you want to store one array to another array then have to give condition for if() whatever you want to do.