0

this code is supposed to insert 3 elements inside the array a which has been dynamically allocated inside the function main

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

int main()
{
    int *a=malloc(3*sizeof(int));
    int i;
    printf("enter the elements of the array");
    for(i=0;i<sizeof(a)/sizeof(int);++i)
    {
        scanf("%d",&a[i]);
    }
    free(a);
    return 0;
}

but it only inserts one element and terminates whereas if i define the array a statistically it works well

0 Answers0