Bucky's C Code Lesson 48 - The Heap

+1 Reynaldo Gunawan · June 13, 2015
I have a problem with this code, as it doesn't really give out the result that it should be given out. 


I've actually followed Bucky's way, almost, step-by-step, but instead of the average and the total, it gives out a bunch of random numbers instead. I would appreciate anyone you can help me with this problem. I have a feeling that the problem is on my compiler. (I'm using Mac OS X, NetBeans as a compiler in an internal terminal)

Post a Reply


Oldest  Newest  Rating
0 K D · June 13, 2015
for starters total is starting off as what ever was previously in that memory location so when u declare the variable have be
int total = 0;
instead of
int total;

the first way says i am going to be using a variable and i want it set to zero.  the second just say "hey give me how ever many bytes an int takes up(usually 4) but i don't want to set it to any thing yet" so when you do that it will just fill that variable with what ever was at that memory location.

i really hope i explained that well... just remember if you don't initialize the variable it has the value of what ever was held  in that memory location.

i really hope this helps...
0 K D · June 13, 2015
bleh horribly written sorry about that lol
0 Reynaldo Gunawan · June 13, 2015
@ K D oh wow, that really really helps. I didn't know that such a minor problem can affect the whole program in general. Now i've learned my lesson. Thank you once more! And what you wrote was actually understandable.
  • 1



One of the most popular languages of all time.

Bucky Roberts Administrator