why this code still runs as space is insufficient in malloc in c....??? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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 Answer
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