0
C++
Why in C++ Sum=a+b; Cout<<sum<<end; is instead of cout<<a+b;
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.
+ 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.
0
the sum is a variable that store the sum of a+b
0
which is best to use
Sum=a+b;
Cout<<sum<<end;
or cout<<a+b;
0
kamran hassan cout<<sum<<end;
0
why