Entering values in an array using malloc function

 #include <stdio.h>

#include <stdlib.h>
int main(){
//printf("The size of int in your computer is %d\n",sizeof(int));
// printf("The size of float in your computer is %d\n",sizeof(float));
// printf("The size of char in your computer is %d\n",sizeof(char));
int * ptr;
ptr=(int *) malloc(6*sizeof(int));

for(int i=0;i<6;i++)
{
    printf("Enter the value of element %d:\n",i+1);
    scanf("%d",&ptr[i]);
}

for(int i=0;i<6;i++)
{
    printf("The value of element %d is:%d\n",i+1,ptr[i]);
   
}
 return 0;
}

Comments