0
Free function question
I was practicing free function and I wrote this piece of code #include <stdio.h> #include <stdlib.h> int main() { int *ptr; ptr = malloc(10*sizeof(*ptr)); /* a block of 10 ints */ if (ptr != NULL) *(ptr+2) = 50; /* assign 50 to third int */ printf("%d\n", *(ptr+2)); /* 50 */ free(ptr); printf("%d\n", *(ptr+2)); return 0; } I expected the output to come as 50 (and a random number) but the output screen showed "No output." Can anyone explain how the code is running?
2 ответов
+ 4
Your code is working. The problem is the Sololearn server. Sometimes it doesn't respond that's why it only shows 'No output'. Just try it a few more times.
+ 1
Me have notice that problem too...