0
Sum of an array : What is a exact behavior of the sum of an array, if sum is not defined?
https://code.sololearn.com/cg39UsZGbz4U/?ref=app Is sum defined inside the library? What is the default value of sum? Can someone explain to me what happened inside this situation, please?
4 Respostas
+ 14
G-G-Garbage value!
+ 10
AFAIK, Since you didn't initialize sum with 0. Garbage value will be initialized to sum.
+ 7
It takes some random values left in computer's secondary memory and uses them. It is always useful or I'd even say necessary to initially assign 0 to sum counting variables and 1 to product counting ones. For the same reason, if you declare an empty array it is better to do //int arr[n] = {};
https://code.sololearn.com/cYy6nsSNLl59/?ref=app
0
Thanks everyone for your fast answers!
@Hatsy I heard you well ahah
@Mr.Robot I took note
@Dimmukhamed Thank you for your detailed answer and advice. I now know the right behavior of an undefined int.