I'm a newbie. Wrote a code to print sum of number from 1 to 10. Here's what happened;
for(a = 1; a<=10; a++)
sum += a;
cout<<sum;
Executing that gave me the correct answer i.e 55
When I execute the following:
for(a = 1; a<=10; a++)
{
sum += a;
cout<<sum;
}
It gives me a complete different and wrong answer i.e 13610152128364555
Why does this happen? What goes wrong when I put curly brackets after for statement?
I hope this is not a silly question.