#include <iostream> using namespace std; int main() { int x = 5, y = 6, z = 50, sum; cout << sum; sum= x + y + z; | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

#include <iostream> using namespace std; int main() { int x = 5, y = 6, z = 50, sum; cout << sum; sum= x + y + z;

sum output is 37 how😫😫

11th Jul 2019, 5:49 PM
Shrusti Singhaniya
2 Answers
+ 4
When declaring variables, always initialize them to avoid any errors.
11th Jul 2019, 6:43 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 2
You are printing the sum before calculating it. sum is not initialized, so I think it is a garbage value.
11th Jul 2019, 6:36 PM
Denise Roßberg
Denise Roßberg - avatar