0

What wrong with this program

It's output should be total sum of array elements but it is printing random long numbers https://code.sololearn.com/c2ZB6FBSqCHX/?ref=app

22nd May 2021, 8:01 AM
Anshul
3 Answers
+ 6
Also, it is recommended to initialize <sum> variable by zero to avoid it from garbage value, being uninitialized.
22nd May 2021, 8:29 AM
Ipang
+ 3
Nikhil You've actually got it the wrong way around, VLAs are legal in C but not standard C++ (although support has become optional since C11 and I would therefore opt for proper dynamic memory allocation either way). Ipang is right in that the sum variable is simply uninitialized.
22nd May 2021, 8:59 AM
Shadow
Shadow - avatar