Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +917541905230, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec

Monday, July 13, 2020

Assignment and shorthand assignment operator in c

Assignment and shorthand operator in C
By Ahmad Irshad | C Programming Tutorial > Assignment & shorthand operaotr in C

Assignment & Shorthand assignment Operators in C | Protec

In C programming, assignment operator = is used to assign value to an variable. For Example: If the vlaue 10 is to be assigned for the variable x it can be assigned as x = 10 

Assignment operator always assign value of its right operand to left operand. That is, x = y which assign the value of y to x. Assignment operator is denoted by = (equal to) sign. It is a binary operator. 

Let's see the the below assignment table:

OperationDescription
x = 10Assigns 10 to variable x
y = (5 + 4) / 2Evaluates expression (5+4)/2 and assign result to y
z = x + yEvaluates x + y and assign result to z
5 = xError, you cannot re-assign a value to a constant
10 = 10Error, you cannot re-assign a value to a constant
Remember: The RHS of assignment operator must be a constant, expression or variable. Whereas LHS must be a variable.

Shorthand assignment operator:

C Provides some special shorthand assignment operators, also known as compound assignment operators. It's called shorthand because it provides a short way to assign an expression to a variable. this operator can be used to connect Arithmetic or Bitwise operators with an Assignment operator. 
For Example: Expressiona = a + 5; can also be written in short a += 5;

Similarly, there are many shorthand assignment operators. Below is a list of shorthand assignment operators in C.

Shorthand assignment operatorExampleMeaning
+=a += 10a = a + 10
-=a -= 10a = a - 10
*=a *= 10a = a * 10
/=a /= 10a = a / 10
%=a %= 10a = a % 10
&=a &= 10a = a & 10
|=a |= 10a = a | 10
^=a ^= 10a = a ^ 10
~=a ~= 10a = a ~ 10
<<=a <<= 10a = a << 10
>>=a >>= 10a = a >> 10

Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +966532621401, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec

Help others by sharing this page.

Ahmad Irshad

Author & Editor

I love blogging, teaching, learning computer science and sharing it to others. I've written and develped this site so that students may learn computer science related tutorials eaisly. MCA / MCITP

0 Comments:

Post a Comment

Please don't enter any spam link in the comment box.


Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +966532621401, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec
Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec
Contact Us