MEMORY ALLOCATION - malloc()

Published: 16 April 2020
on channel: Solution Manual
16
0

int main()
{
int i,n,*p;
//Allocate the memory based on user given size

printf("\n Enter the Number of Elements\n");
scanf("%d",&n);
p=(int*)malloc(n*sizeof(int)); // if elements is equal to 2 then 2x4(size of int)=8 bytes will be allocated

// PRINT THE MEMORY LOCATION
for(i=0;i less than n;i++)
{
printf("\nMemory Location of %d is :::: %d",i,&p[i]);
}
// GET THE ELEMENTS FROM USER ON MEMORY LOCATIONS

for(i=0;i less than n;i++)
{
printf("\n Enter the Element %d \t ",i);
scanf("%d",&*(p+i));
}

//PRINT THE ELEMENTS
printf("\n ::::Elements::::\n");

for(i=0;i less than n;i++)
{
printf("\n%d\n",*(p+i));
}
return 0;
}


On this page of the site you can watch the video online MEMORY ALLOCATION - malloc() with a duration of hours minute second in good quality, which was uploaded by the user Solution Manual 16 April 2020, share the link with friends and acquaintances, this video has already been watched 16 times on youtube and it was liked by 0 viewers. Enjoy your viewing!