'Generating not fully filled array with C

Is it possible to generate an array of 5 elements, which can be not filled in full?

The array I want to create can have a maximum size of 5 elements, as shown in this code:

#include <stdio.h>
#define M 5
void sort (int *, int);
void create (int *tab, int size);
void display();
void insert();
void del();
void exit();


int main()
{
    int c;
    int arr[M];
    printf("Choose an option: \n");
    printf("1. Input values to the array (MUST BE DONE FIRST).\n");
    printf("2. Show elements of the array.\n");
    printf("3. Update array.\n");
    printf("4. Remove element from the array.\n");
    printf("5. Sort array. \n");
    printf("6. Exit program.\n");
    printf("\nYour option: ");
    scanf("%d", c);
    
    switch(c)
    {
        case 1:
        create(arr, size);
        break;
        
        case 2:
        display();
        break;
        
        case 3:
        insert();
        break;
        
        case 4:
        del();
        break;
        
        case 5:
        sort(int *, int);
        break;
        
        case 6:
        exit();
        break;
    }
}

void create(int *tab, int size)
{
    printf("Input amount of elements in array: ");
    scanf("%d", &size);
    
}

That's what I've done so far. In the previous version of the code, instead of filling only several elements from all 5, program filled a whole array, putting random values in cells higher than amount of input elements (e.g. in an array which had to have only three elements filled, it was filled fully, except arr[3] and arr[4] were displaying unwanted values:


 ******** MAIN MENU *********
 1. Create table (CREATE IT FIRST!!!!) 
 2. Display table
 3. Add element
 4. Delete element
 5. EXIT
 Enter your option : 1

Input amount of elements: 3

 ******** MAIN MENU *********
 1. Create table (CREATE IT FIRST!!!!) 
 2. Display table
 3. Add element
 4. Delete element
 5. EXIT
 Enter your option : 3
Tab[0]: 1
Tab[1]: 2
Tab[2]: 3
Tab[3]: 4
Tab[4]: 5
Tab[5]: 6
Tab[6]: 7
Tab[7]: 8

 ******** MAIN MENU *********
 1. Create table (CREATE IT FIRST!!!!) 
 2. Display table
 3. Add element
 4. Delete element
 5. EXIT
 Enter your option : 2
1 2 3 4 5 
 ******** MAIN MENU *********
 1. Create table (CREATE IT FIRST!!!!) 
 2. Display table
 3. Add element
 4. Delete element
 5. EXIT
 Enter your option : 

So, is it possible to generate a not fully filled array in C?



Solution 1:[1]

No, you can initialize partially an array, but the full array will be filled. The non initialized elements will be zeroed.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Luis Colorado