Can i use malloc() ?

malloc
sigabrt

#1

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?


#2

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


#3

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!


#4

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