Assignment Operators in C Language


Assignment operators in C Language:

    • In C programs, values for the variables are assigned using assignment operators.
    • For example, if the value “10″ is to be assigned for the variable “sum”, it can be assigned as “sum = 10;”
    • Other assignment operators in C language are given below.
Operators
Example
 Explanation 
Simple assignment operator
=
sum=10
10 is assigned to variable sum
Compound assignment operators
+=
sum+=10
This_is_same_as_sum=sum+10…………
-=
sum-=10
This is same as sum = sum-10
*=
sum*=10
This is same as sum = sum*10
/+
sum/=10
This is same as sum = sum/10
%=
sum%=10
This is same as sum = sum%10
&=
sum&=10
This is same as sum = sum&10
^=
sum^=10
This is same as sum = sum^10

Example program for C language assignment operators:

    • In this program, values from 0 – 9 are summed up and total “45″ is displayed as output.
    • Assignment operators such as “=” and “+=” are used in this program to assign the values and to sum up the values.

Output:

Total = 45




 Continue on types of C language operators:

S.no
Types of Operators
             Description              
1
Arithmetic_operatorsThese are used to perform mathematical calculations like addition, subtraction, multiplication, division and modulus
2
Assignment_operatorsThese are used to assign the values for the variables in C programs.
3
Relational operatorsThese operators are used to compare the value of two variables.
4
Logical operatorsThese operators are used to perform logical operations on the given two variables.
5
Bit wise operatorsThese operators are used to perform bit operations on given two variables.
6
Conditional (ternary) operatorsConditional operators return one value if condition is true and returns another value is condition is false.
7
Increment / decrement operatorsThese operators are used to either increase or decrease the value of the variable by one.
8
Special operators&, *, sizeof( ) and ternary operators
www.cinterviews.com appreciates your contribution please mail us the questions you have to cinterviews.blogspot.com@gmail.com so that it will be useful to our job search community

No comments: