Solved

allocate memory

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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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…
Six Sigma Control Plans

696 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