Free function question | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson

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?

10th Jan 2019, 7:35 AM
Hardik Sharma
Hardik Sharma - avatar
2 Answers
+ 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.
10th Jan 2019, 8:01 AM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
+ 1
Me have notice that problem too...
10th Jan 2019, 8:50 AM
KrOW - avatar