C Program to check some aspects of Dynamic Memory Allocation in C


 

// Program by Akash Tripathi (@proakash256) 
#include <stdio.h>
#include <stdlib.h>
void display(int *ar , int *n)
{
    for (int i = 0i < *ni = i + 1)
        printf("%d"ar[i]);
    return;
}
int main()
{
    int n;
    scanf("%d" , &n);
    int *ar = (int *)malloc(n * sizeof(int));
    for (int i = 0i < ni = i + 1)
        scanf("%d", &ar[i]);
    display(ar , &n);
    free(ar);
    for (int i = 0i < ni = i + 1)
        printf("%d"ar[i]); // Doesn't work
    return 0;
}

Comments