Professional Documents
Culture Documents
• Arithmetic Operators
• Increment and Decrement Operators
• Assignment Operators
• Relational Operators
• Logical Operators
• Bitwise Operators
• Conditional Operators
• Shift Operators
• Special Operators
Arithmetic Operators:
Output:
The operators +, - and * computes addition, subtraction, and multiplication
respectively.
It is because both the variables a and b are integers. Hence, the output is also an
integer. The compiler neglects the term after the decimal point and shows answer
2 instead of 2.25.
The modulo operator % computes the remainder. When a=9 is divided by b=4, the
remainder is 1. The % operator can only be used with integers.
For Example:
Output:
Here, the operators ++ and -- are used as prefixes. These two operators can also
be used as postfixes like a++ and a--.
Assignment Operators:
Relational Operators:
For Example:
Output:
Logical Operators:
An expression containing logical operator returns either 0 or 1 depending upon
whether expression results true or false. Logical operators are commonly used in
decision making in C programming.
For Example:
Output:
Bitwise Operators:
During computation, mathematical operations like: addition, subtraction,
multiplication, division, etc are converted to bit-level which makes processing
faster and saves power.
Let us suppose the bitwise AND operation of two integers 12 and 25.
For Example:
Output:
Bitwise OR Operator:
For Example:
Output:
The result of bitwise XOR operator is 1 if the corresponding bits of two operands
are opposite. It is denoted by ^.
For Example:
Output:
Conditional Operators:
For Example:
In the above code, we are taking input as the 'age' of the user. After taking input,
we have applied the condition by using a conditional operator. In this condition,
we are checking the age of the user. If the age of the user is greater than or equal
to 18, then the statement1 will execute, i.e., (printf("eligible for voting"))
otherwise, statement2 will execute, i.e., (printf("not eligible for voting")).
Outputs:
As we can observe from the above two outputs that if the condition is true, then
the statement1 is executed; otherwise, statement2 will be executed.
Another Example:
In the above code, we have declared two variables, i.e., 'a' and 'b', and assign 5
value to the 'a' variable. After the declaration, we are assigning value to the 'b'
variable by using the conditional operator. If the value of 'a' is equal to 5 then 'b'
is assigned with a 3 value otherwise 2.
Output: