Solved

allocate memory

Posted on 2004-03-25
7
227 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
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.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now