The first code:
#include <iostream>
using namespace std;
int main () {
int a=80;
if( a == 10 ) {
cout << "Value of a is 10 " << endl;
} else if( a == 20 ) {
cout << "Value of a is 20" << endl;
} else if( a == 30 ) {
cout << "Value of a is 30" << endl;
}else {
cout << "Value of a is not matching" << endl;
}
cout << "Exact value of a is : " << a << endl;
return 0;
}
result: Value of a is not matching
Exact value of a is: 80
The 2nd code:(just changed a == 20 to a=20)
#include <iostream>
using namespace std;
int main () {
int a=80;
if( a == 10 ) {
cout << "Value of a is 10 " << endl;
} else if( a = 20 ) {
cout << "Value of a is 20" << endl;
} else if( a == 30 ) {
cout << "Value of a is 30" << endl;
}else {
cout << "Value of a is not matching" << endl;
}
cout << "Exact value of a is : " << a << endl;
return 0;
}
The result is:Value of a is 20
Exact value of a is: 20.
so, why appeared so difference in the results just changing == to =?
any help will be thankful.