0
#include <iostream> using namespace std; int main() { int a = 100; a = 50; cout << a; a = 12; cout << a; return 0; } this code shows output as 5012 why isn't it showing 12? please help
9 Answers
+ 11
With the first command cout<<a the program print the value of variable a which at this time it is 50. With the second command cout<<a the program print again the value of variable a which at this time it is 12. So the program finally print 5012.
+ 5
If you do not want to delete any commands you could comment the command cout<<a. The command is shown on the next line:
//cout<<a;
+ 1
when you print the line cout<< a ; this mean to print a value of a and after print a new value assigned by you than print again new value.
0
wht should i do to get just 12 as output with the same program?
please help
0
remove the first cout ; u will get only 12 as answer
0
every time you declare cout it's written to the output, its not like java or something where variables have room to be changed while the program is still running, or at least thsts what i think haha
0
because you use output function for each assigned value of a ..
0
you can assign different variables for different values...why to make it more confusing...or you can just use /*.....*/ to make the decond cout for 50 as an comment...then program will give an output just 12 which you want..@harshit
0
remove first cout