News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

array elements fills with random value after 10th element codeblocks 13.12

Started by meyumraaj, June 10, 2015, 03:02:44 PM

Previous topic - Next topic

meyumraaj

I am a new user to Codeblocks and beginning to learn C; I have this problem since the beginning

Whenever i have array with more then 10 elements and while i try to iniatilize the element value to 0 using a loop; after 10th element all the array element fills with random value. I have attached the snapshot for reference.

Any suggestion would be appreciated :)


stahta01

Edit: Most debuggers and likely CB does the same shows the value before the line in debugger is executed!
I suggest doing a break point after the line.


Read the Rules and the FAQs.
http://forums.next.codeblocks.org/index.php/topic,9996.0.html
http://wiki.codeblocks.org/index.php?title=FAQ

Edit2: Post a build log and your code on a site that teaches how to program.
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F

Tim S.
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

stahta01

Please read the debugger info it might help.
Edit: Sorry, I misread your question; did NOT realize it was on how to use the debugger instead of on how to code.

http://wiki.codeblocks.org/index.php?title=Debugging_with_Code::Blocks

Tim S.
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

meyumraaj

I am using codeblocks in windows 8. I have a doubt that if there is some tweak/setting/config i have to adjust in codeblock.

somehow array longer then 10 element is not being initialized.

How could debugger have something to do with it ???

oBFusCATed

This is a bug in the debugger plugin.
Do you see the first line in your watches windows - 0 <repeats 11 times>?
This means that the debugger is trying to be smart and tells us that this array has 11 zeroes at the first 11 elements.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

meyumraaj

Its not the debugger which is initializing the array values to 0

For Loop in the code is initializing value of 0 in each and every elements in the array but when for loop reached 10th element all the array values  goes back to random values.

The problem is; I can't initialize array elements value to 0.

oBFusCATed

I think you're wrong here.

One easy way to find out is to add another loop after your initialization loop that will print the values of the array on the screen.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

raynebc

He's being misled by it saying counts[0] is a series of 11 zeroes and that counts[1] is a nonzero value.  If the bug that oBFusCATed mentioned is that it should instead read that counts[0] is 0 repeated 11 times and that counts[11] is nonzero, that would seem to be the cause for confusion.

meyumraaj

It was just my confustion

Array was initialized properly and debugger was saying 11 times 0 :)

Thank You Very Much  oBFusCATed and raynebc :D