ans 2

mail@pastecode.io avatar
unknown
c_cpp
3 years ago
557 B
0
Indexable
Never
#include<stdio.h>
#include<stdlib.h>

int main(int argc,char** argv)
{
    int* arr;
    int n=5;
    // Dynamically allocate memory using calloc()
    arr = (int*)calloc(n, sizeof(int));
        // Memory has been successfully allocated
        printf("Memory successfully allocated using calloc.\n");
        for (int i = 0; i < n; ++i) {
            arr[i] = i + 1;
        }

        printf("The elements of the array are: ");
        for (i = 0; i < n; ++i) {
            printf("%d, ", arr[i]);
        }
    }
    return 0;
}