Clouds
Home
Tutorial of C language
Computer Language
Introduction to C
Programming in C
Structure of C program
Variable in C
Datatypes in C
Token in C
Operator in C
Precedence of C Operator
Assignment Operator in C
Logical Operator in C
Bitwise Operator in C
Ternary Operator in C
C Input Output
Pointers in C
Storage Classes of C
Control Structure of C
C Decision Making Statement
C Looping Statement
C Jumping Statement
C Function
Function Call By Value
Function Call By Reference
C Input Output Function
C Structure
Array in C
Union in C

Assignment Operators

The value can be stored in variables with the use of assignment operator. This assignment operator "=" is used for assignment statement.
Operator Description Example
= Simple assignment operator, Assigns values from right side operands to left side operand C = A + B will assigne value of A + B into C
+= Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand C += A is equivalent to C = C + A
-= Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand C -= A is equivalent to C = C - A
*= Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand C *= A is equivalent to C = C * A
/= Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operand C /= A is equivalent to C = C / A
%= Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operand C %= A is equivalent to C = C % A
<<= Left shift AND assignment operator C <<= 2 is same as C = C << 2
>>= Right shift AND assignment operator C >>= 2 is same as C = C >> 2
&= Bitwise AND assignment operator C &= 2 is same as C = C & 2
^= bitwise exclusive OR and assignment operator C ^= 2 is same as C = C ^ 2
|= bitwise inclusive OR and assignment operator C |= 2 is same as C = C | 2

Example1:
Let x=1
x=x+1 can also be written as
x+=1
Similarly
x=x-1 can also be written as
x-=1
Similarly
x=x*1 can also be written as
x*=1
Similarly
x=x/1 can also be written as
x/=1

Example2:
				void  main()
				{
				   int a = 21;
				   int c ;
				   c =  a;
				   printf("the value of c = %d\n", c );
				   c +=  a;
				   printf("the value of c = %d\n", c );
				   c -=  a;
				   printf("the value of c = %d\n", c );
				   c *=  a;
				   printf("the value of c = %d\n", c );
				   c /=  a;
				   printf("the value of c = %d\n", c );
				   c  = 200;
				   c %=  a;
				   printf("the value of c = %d\n", c );
				   c <<=  2;
				   printf("the value of c = %d\n", c );
				   c >>=  2;
				   printf("the value of c = %d\n", c );
				   c &=  2;
				   printf("the value of c = %d\n", c );
				   c ^=  2;
				   printf("the value of c = %d\n", c );
				   c |=  2;
				   printf("the value of c = %d\n", c );}
				


Logical Operator in C >>
Bitwise Operator in C >>
Ternary Operator in C >>
C Input Output >>
Pointers in C >>


Home Clouds