You are not logged in. Please login at www.codechef.com to post your questions!

×

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?

asked 05 Oct '14, 09:55

pritish_yuvraj's gravatar image

1★pritish_yuvraj
1613
accept rate: 0%

retagged 05 Oct '14, 11:33

nisargshah95's gravatar image

3★nisargshah95
264511

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

(05 Oct '14, 11:33) nisargshah953★

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

link

answered 05 Oct '14, 10:28

geeksoul's gravatar image

1★geeksoul
3013
accept rate: 0%

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!

link

answered 05 Oct '14, 12:56

xiaoyu_02's gravatar image

2★xiaoyu_02
5531923
accept rate: 5%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×66
×26

question asked: 05 Oct '14, 09:55

question was seen: 3,220 times

last updated: 05 Oct '14, 12:56