why this code still runs as space is insufficient in malloc in c....??? | Sololearn: Learn to code for FREE!
0

why this code still runs as space is insufficient in malloc in c....???

#include<stdio.h> #include<stdlib.h> int main(){ int *x; x=(int*)malloc(1); for(int i=0;i<9;i++){ x[i]=i+10; if (x!=NULL){ *(x+2)=50;} printf("%d\n",x[i]); } return 0; }

7th Oct 2021, 9:42 AM
Hß║úo Nguyß╗ůn Thi├¬n
Hß║úo Nguyß╗ůn Thi├¬n - avatar
1 Antwort
0
It seems to mess up whatever comes in first from stdin. Then gives x 8 bytes of data and continues. https://code.sololearn.com/cyjdlkx88aDn/?ref=app
7th Oct 2021, 9:54 AM
Slick
Slick - avatar