Short hand assignemnt operators are also known as compound assignment operator. The advantage of using short hand assignment operator is that it requires less typing and hence provides efficiency.
#include
int main ()
{
using std::cout;
using std::endl;
int a = 3;
cout << "Value of a is : "<< a << endl;
a = a + 1;
cout << "Value of a is : "<< a << endl;
a = a - 1;
cout << "Value of a is : "<< a << endl;
a = a * 2;
cout << "Value of a is : " << a << endl;
a = a / 2;
cout << "Value of a is : " << a << endl;
a = a % 2;
cout << "Value of a is : " << a << endl;
return 0;
}
#include
int main ()
{
using std::cout;
using std::endl;
int a = 3;
cout << "Value of a is : " << a << endl;
a += 1;
cout << "Value of a is : " << a << endl;
a -= 1;
cout << "Value of a is : " << a << endl;
a *= 2;
cout << "Value of a is : " << a << endl;
a /= 2;
cout << "Value of a is : " << a << endl;
a %= 2;
cout << "Value of a is : " << a << endl;
return 0;
}
a = a + 1 is same as a += 1 and
a = a - 1 is same as a -= 1 and
a = a * 1 is same as a *= 1 and
a = a / 1 is same as a /= 1 and
a = a % 1 is same as a %= 1
Please do comment if you don't understand any part or want to know more or just want to say thanks. I love programming and love to teach my friends. Your suggestions and appreciation will make this blog much better.
View the original article here
0 komentar:
Posting Komentar