I would like to be able to do this in order to do some manipulation with the two bytes eventually...can anybody show me how to do this?
I would like to be able to do this in order to do some manipulation with the two bytes eventually...can anybody show me how to do this?
This?Code:char *ptr ptr = malloc(2 * sizeof(char));
The only good is knowledge and the only evil is ignorance.
~Socrates
hmm... but if you know that the array will consist of exactly two bytes, why bother with dynamic memory allocation?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
ROFL!
Laserlight has the right idea. Depending on what you're doing you can perhaps just declare a local array or something like that. Even if it has to exist longer than the lifetime of the function call, you still have return values and out-parameters as an option.
Using dynamic memory allocation for something so small is like going to the shop to buy exactly two grains of salt.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
From now on I'm going to dynamically allocate my bools
lol you guys are bullies...i know its easy to say it now, but when i first read that i had to do that i thought to myself the same thing, like whats the point of dynamically allocating a set amount of bytes. but then i thought my prof probably knows more about C than I do so I just went with it.
but thanks guys, appreciate the help.
It's just that 2 bytes is such a tiny amount... easily representable within a basic data type. Perhaps the professor simply wanted the students to be clear on the different uses of memory. Once the concepts are clear, then one can decide whether there is efficiency of one type over another.