0

mujhe yeh wala program samaj main nahi aaya jab k: int a=100; b=50; toh iss ka answer 50 kaisa aaya?

#include <iostream> using namespace std; int main() { int a = 100; a = 50; cout << a; return 0; }

12th Jul 2016, 11:09 AM
himanshu arora
6 Respostas
+ 2
simple, variable a declared with value 100, then in next line value assigned '=' is 50 hence now variable value updated/overwrite. check in program u wrote a=50 so u change variable 'a' not 'b'
12th Jul 2016, 11:20 AM
VISHAL PRAJAPATI
VISHAL PRAJAPATI - avatar
+ 1
it's bcz the first time a is having 100value in it.. but on the very next line what is happening is we are again assigning the value of a equal to 50 rather than 100.. bcz in C++ the complier execute the latest value which was assign.. and in your case a=50 is the latest one.. but if you write like this int a = 50; a= 100; ur output will be 100 bcz now a=100 will be the latest for compiler.. I hope it's help u bro :)
12th Jul 2016, 11:31 AM
Vinod Bahadur Thapa
Vinod Bahadur Thapa - avatar
+ 1
u ask for a,b and in program there is no 'b' only a....
12th Jul 2016, 11:37 AM
VISHAL PRAJAPATI
VISHAL PRAJAPATI - avatar
+ 1
bhaijaan a=50 hi output nikal raha hai.. hosakta hai ki second wala 'a' he Sayad compile hota hai
12th Jul 2016, 6:44 PM
meherDev
meherDev - avatar
0
write in english man.see your code it is written a equals 50 in 3rd line or 4th line
12th Jul 2016, 11:12 AM
Shirshak Bajgain
Shirshak Bajgain - avatar
- 1
see the cout statement
12th Jul 2016, 4:28 PM
Ayush chadha
Ayush chadha - avatar