0

C++

Why in C++ Sum=a+b; Cout<<sum<<end; is instead of cout<<a+b;

11th Jun 2018, 2:04 AM
kamran hassan
kamran hassan - avatar
6 odpowiedzi
+ 5
kamran hassan Depends on your program. If you are going to use the value of the sum of a and b a lot, might as well store it in a variable and avoid recomputation. In the above context, it doesn't make much difference.
11th Jun 2018, 2:14 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
why do you use variable ? so that it can be changed easily. consider that you have to output sum like hundreds of time.suddenly you need to add or remove a number from every output and print updated sum. would you do it hundreds of times or update the definition of variable sum.. This is just scenerio.
11th Jun 2018, 2:24 AM
Sunil Thakali
Sunil Thakali - avatar
0
the sum is a variable that store the sum of a+b
11th Jun 2018, 2:12 AM
Blizz
Blizz - avatar
0
which is best to use Sum=a+b; Cout<<sum<<end; or cout<<a+b;
11th Jun 2018, 2:13 AM
kamran hassan
kamran hassan - avatar
0
kamran hassan cout<<sum<<end;
11th Jun 2018, 2:14 AM
Blizz
Blizz - avatar
0
why
11th Jun 2018, 2:14 AM
kamran hassan
kamran hassan - avatar