Solved

allocate memory

Posted on 2004-03-25
7
231 Views
Last Modified: 2010-04-17
How do I initialise p in the declaration statement :
in my code I have p= malloc(n*4);/*allocate memory*/
It is not running properly.
also:
hold = p[j];
0
Comment
Question by:mlmcguire
  • 2
  • 2
7 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 10683457
What do you mean by "not running properly"?
0
 

Author Comment

by:mlmcguire
ID: 10683562
its telling me that it cannot convert int to something. I was working on it 2days ago.
0
 
LVL 23

Accepted Solution

by:
chensu earned 50 total points
ID: 10683579
So it is a compiling error. You need to cast it. For example,

int *p = (int *)malloc(n * sizeof(int));
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10686976
>> (n * sizeof(int))

mlmcguire, not that this is a better way of doing it than your original ( n * 4 ) -> because the size of the primitive data types in C will depend upon the platform on which your program is running.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10686979
>> not that

note* that....
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question