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

14th Aug 2016, 6:16 PM
Harshit
9 Respostas
+ 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.
14th Aug 2016, 6:34 PM
GTimo
GTimo - avatar
+ 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;
14th Aug 2016, 6:42 PM
GTimo
GTimo - avatar
+ 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.
20th Aug 2016, 5:26 PM
Kuldeep Kashyap
0
wht should i do to get just 12 as output with the same program? please help
14th Aug 2016, 6:37 PM
Harshit
0
remove the first cout ; u will get only 12 as answer
14th Aug 2016, 10:51 PM
Asim
Asim - avatar
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
15th Aug 2016, 10:06 AM
Julian Hodge
Julian Hodge - avatar
0
because you use output function for each assigned value of a ..
15th Aug 2016, 3:59 PM
Tarun kumar parashar
Tarun kumar parashar - avatar
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
4th Sep 2016, 6:00 AM
Aman Saxena
Aman Saxena - avatar
0
remove first cout
18th Sep 2016, 8:54 AM
Ankit Panwar
Ankit Panwar - avatar