Hi,
This is the code fragment:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
int main()
{
int* bugs_bunny;
bugs_bunny = (int*)malloc(3*sizeof(int));
memset(bugs_bunny, 5, 3*sizeof(int));
printf("bugs_bunny[0] %d\n",bugs_bunny[0]);
bugs_bunny[0] = 17;
printf("bugs_bunny[0] %d\n",bugs_bunny[0]);
return (1);
}
The outcome is:
bugs_bunny[0] 84215045
bugs_bunny[0] 17
Why is the value printed for bugs_bunny[0] using memset producing garbage value while the 2nd one is printing the right result?
Thanks.