ive dynamically allocated an array of two bytes using
char *ptr1 = (char *)malloc (2*sizeof(char));
now how can I print the number of ones and zeros in the memory allocated?
ive dynamically allocated an array of two bytes using
char *ptr1 = (char *)malloc (2*sizeof(char));
now how can I print the number of ones and zeros in the memory allocated?
Someone was here asking this exact question with the same code and everything earlier. You should search for it.
that was me, but i was asking how to find the hamming distance and havent been able to figure it out thus far. so im taking a step back and trying to figure out how to just print the 0 and 1s first and work my stuff out from there.
No, I mean someone was asking this very question and you should have searched before you asked.
haha oh jeez, that guy is more than likely in my class. small world. i just assumed you meant me, but thanks for directing me.
And of course, for any given system, if you do this twice in a row, it may give exactly the same result or a completely different result. It is COMPLETELY unpredictable what the memory contains after malloc() - it is "whatever happens to be in that memory", and that could be all ones, all zeros or any of the 65534 other possible combinations. A LIKELY scenario is that if you have not allocated the memory previously, it contains zero. But there is no guarantee - and in particular, Visual Studio (for Windows), when the code is in debug mode will fill the malloc() memory with a pattern (0xCD?) .
I fail to see the point of such an excercise. It would be a better excercise to produce a 16-bit random number and calculate whatever it is you want to calculate (hamming distance, number of ones and zeros or whatever).
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.