Can i use malloc() ?



I used malloc() in one of my programs. I am getting SIGABRT which usually occurs due to error in memory allocation. So how to overcome this?


Pritish Thumbs up for the question! I also have the same doubt!


Hi Pritish! Most probably, you haven’t done the allocation correctly. Like for example, if you want to allocate memory to a data of type long long then you need to write y=(long long *)malloc(sizeof(long long)), which usually people mistake up with y=(int *)malloc(sizeof(long long)) or y=(long long *)malloc(sizeof(int)).

If there’s some other issue,please comment!


There might be a bug in your handling of the pointers.