Professional Documents
Culture Documents
PF Mid Assignment
PF Mid Assignment
Programming Fundamentals:
Section: C
Department: BSCS
*// write a program that performs all compound assignment operations on an integer.
#include<iostream>
using namespace std;
int main()
//Program to perform all compound assignment operations on an
integer
{
cout << "all compound operation on an integer:\n\n";
int a=5,b=5;
a+=b;
cout << "the value is :"<< a << '\n';
a-=b;
cout << "the value is :"<< a << '\n';
a*=b;
cout << "the valus is :"<< a << '\n';
a/=b;
cout << "the valus is :"<< a << '\n';
a%=b;
cout << "the value is :"<< a << '\n';
system("pause");
return 0;
Result:
10
5
25
5
0
Example:
n += 10;
is equivalent to
n = n + 10
Both assignments are equivalent and perform the same operation. Both statements add 10 in the
current value of n. all the other mathematical operators can also be combined with assignment
operator. Some examples of assignment operators are as follows
A += 10 is equivalent to A = A + 10
A -= 10 is equivalent to A = A – 10
A *= 10 is equivalent to A = A * 10
A /= 10 is equivalent to A = A / 10
A %= 10 is equivalent to A = A % 10
The addition-assignment (+=) and subtraction-assignment (-=) operators can also have a
left operand of pointer type, in which case the right-hand operand must be of integral
type. The result of a compound-assignment operation has the value and type of the left
operand
n &= MASK;