Sunday, 10 September 2017

Assignment Operator


Question: What is the name = operator in mathematics?
Answer: is equal to

Write In C language terminology this operator is known as Assignment operator which is use to assign right hand side value into left hand size variable with overwrite mode. An assignment operator has following attributes.
  • Place right hand side data into left hand side variable.
  • If left hand side variable has some data before then it will be lost because an assignment operator overwrite earlier data.
  • Binary operator needs two operand
  • Used in equation.
  • Lower priority operator but higher priority than comma. 


Assignment Operator C Language

Example


int a,b,c;
    a=10;
    b=20;

Shorthand

Shorthand method is another way to use assignment operator which help in compact programing.


Operator symbol
Name of the operator
Example
Equivalent construct
+=
Addition assignment
x += 4;
x = x + 4;
-=
Subtraction assignment
x -= 4;
x = x – 4;
*=
Multiplication assignment
x *= 4;
x = x * 4;
/=
Division assignment
x /= 4;
x = x / 4;
%=
Remainder assignment
x %= 4;
x = x % 4;


 






int a,b,c;
     a=10;
     b=20;
     printf("\n\tA=%d\tB=%d",a,b);
     a+=5;
     b-=5;
     c=a+b;
     printf("\n\tA=%d\tB%d\tC=%d",a,b,c);
     a*=2;
     b/=2;
     c%=10;
     printf("\n\tA=%d\tB%d\tC=%d",a,b,c);

No comments:

Post a Comment