Solved

allocate memory

Posted on 2004-03-25
7
221 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:mayankeagle
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:mayankeagle
ID: 10686979
>> not that

note* that....
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Purpose To explain how to place a textual stamp on a PDF document.  This is commonly referred to as an annotation, or possibly a watermark, but a watermark is generally different in that it is somewhat translucent.  Watermark’s may be text or graph…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
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 …
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…

708 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

19 Experts available now in Live!

Get 1:1 Help Now