Dynamic Array Allocation

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

int main() {
    // Dynamic array allocation
    int *dynamicArray;
    int size;

    printf("Enter the size of the array: ");
    scanf("%d", &size);

    dynamicArray = (int *)malloc(size * sizeof(int));

    if (dynamicArray == NULL) {
        printf("Memory allocation failed.\n");
        return 1;
    }

    // Use the dynamically allocated array

    // Free the allocated memory
    free(dynamicArray);

    return 0;
}
chevron_left
chevron_right

Leave a comment

Your email address will not be published. Required fields are marked *

Comment
Name
Email
Website