------------------------------------------------------------------------------
MC logo
Variable-Sized Arrays
[^] Code Examples
------------------------------------------------------------------------------
<<Dynamic Array Allocation dynarr4.c C Strings>>
#include <stdio.h>

// Read in the indicated number of numbers, then print them backwards.
void rne(int arr[], int size)
{
        for(int i = 0; i < size; ++i)
                scanf("%d", &arr[i]);

        printf("----------------------------------------------------\n");
        int i;
        for(i = size-1; i >= 0; --i)
                printf("%d ", arr[i]);
        printf("\n----------------------------------------------------\n");
}

main()
{
        // Allocate with new C99 variable-sized arrays.
        int size;
        scanf("%d", &size);
        int arr[size];
        rne(arr, size);
}
<<Dynamic Array Allocation C Strings>>