?
Solved

allocate memory

Posted on 2004-03-25
7
Medium Priority
?
260 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 200 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
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 …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

650 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