August 6th, 2013, 04:46 AM
when the array size is 100, it does not crash
but when i make it higher or less than 100, it crashes. what causes the problem?
August 6th, 2013, 04:57 AM
number[variable]. What does "variable" evaluate to?
Maybe you meant to write:
Was that it ?
It's either change the whole loop to "counter" OR "variable". It's your pick.
August 6th, 2013, 05:03 AM
well that was embarrassing -_- simple bug and couldn't find it! Thank you! it works now
Originally Posted by C learner
August 6th, 2013, 05:07 AM
lol no problem
August 6th, 2013, 05:18 AM
First of all post your code in text format dont post screenshots of code.
And Where did u initialize value of variable.?
That's why u r getting such outputs.
August 6th, 2013, 09:42 AM
As already pointed out, variable was never initialized, so it contains a garbage value which is whatever just happened to be in memory at that location from previous use of that memory location.
The probable reason for it crashing unless the array size was 100 would be that that size of the array placed variable at a memory location that just happened to have a garbage value small enough to be reasonable or at least positioned that array element at a location that did not visible harm. When you made the array a different size, then variable was positioned at a different location which had a garbage value that did cause a crash.
August 6th, 2013, 06:11 PM
also you effectively wrote
for (i=0; i<=MAX; ++i)
which consumes MAX+1 values.
[/code] are essential for python code and Makefiles!