There was another thread on this topic that I was going to reply to but it was closed.
This is my code:
When using printf to display the value of result[0], it always says the value is 0, not 5. It displays result[1] and result[2] correctly as 2 and 3.Code:#include <stdio.h> int main() { int *result; result = (int *) malloc(3); result[0] = 5; result[1] = 2; result[2] = 3; free(result); printf("%d \n", result[0]); return 0; }
What is wrong?