variables | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

variables

when you write int a = 100; a = 50; cout << a; the answer is 50 so.. why you should still type 100 on (int a=)

25th Apr 2017, 3:06 AM
agung pramudji
agung pramudji - avatar
5 Answers
+ 4
you could initialize the number to the variable when you declare your variable or later depending on the program
25th Apr 2017, 3:12 AM
chris
chris - avatar
+ 3
to add.... if you cout<<a without loading it with a=50, it will display 100...this code is showing like chris said, that you can temporarily change whats inside "a" if you need to later, or leave it with the current value
25th Apr 2017, 3:16 AM
Buck Gillispie
Buck Gillispie - avatar
+ 2
You can also write it as int a; a=50; cout<<a; It is not necessary to declare at the time of declaration.
25th Apr 2017, 3:13 AM
Karan Vaity
Karan Vaity - avatar
0
You can just type "int a;". No necessary to initialize it with a value in this case.
25th Apr 2017, 3:13 AM
Jeth
Jeth - avatar
0
thanks all
26th Apr 2017, 4:19 AM
agung pramudji
agung pramudji - avatar