I'm workig on memory allocation and trying to understand this code.
output prints
i=0
d=149909512 - How is d getting these numbers?
*d=0,
i=5, d[i]135145.
how can d have these numbers if malloc returns the address of the beginning of allocated memory or NULL if it fails.
output prints
i=0
d=149909512 - How is d getting these numbers?
*d=0,
i=5, d[i]135145.
how can d have these numbers if malloc returns the address of the beginning of allocated memory or NULL if it fails.
Code:
#include<stdio.h>
int main(void)
{
int i, *d;
/*printf("%d\n %d",i,*d);*/
d = malloc( 5 * sizeof(int) );
printf("i=%d\n d=%d\n *d=%d\n",i,d,*d);
for(i = 0; i < 5; i++)
d[i] = i + 100;
printf("i=%d\n d[i]%d",i,d[i]);
}
Comment