Technologies

C

Operators in C Languages
(adsbygoogle = window.adsbygoogle || []).push({});
** Operators : ** C support a rich set of built in operators. An operator is a symbol that tells the computer to perform certain mathematical or logical manipulations. Operators are used in the programs to manipulate data and variables.

C Operators can be classified in to the following categories :

#
1. Arthimetic Operators :

C provides all the basic arithmetic operators.

The operators +,-, * and / all work the same way as they do in other languages. These can operator on any built in data type allowed in C.

Integer division operation truncates any fractional part(or) it gives the quotient of an integer division.

The modulo division operation products the remainder of an integer division.

All arithmetic operators are binary operators, because they act on two operands, The operators *, /, % will be given the highest priority over + and -.

When equal priority operators are there in an expression, the operators will be evaluated from left to right i.e they follow left to right associativity

** Note : **

# Integer Arithmetic

**Example : **

For a = 14 and b = 4, we have the following results :

a - b = 10, a + b = 18, a * b = 56

a / b = 3 (decimal part truncated), a % b = 2 (reminder of division)
# Real arithmetic :

# Mixed mode arithmetic :

(adsbygoogle = window.adsbygoogle || []).push({});
(adsbygoogle = window.adsbygoogle || []).push({});

CLanguage

Friday, 31 Mar 2017

139

0

0

C Operators can be classified in to the following categories :

**Arithmetic Operators****Relational Operators****Logical Operators****Assignment Operators****Increment and Decrement Operators****Conditional Operators****Bitwise Operators****Special Operators**

The operators +,-, * and / all work the same way as they do in other languages. These can operator on any built in data type allowed in C.

Integer division operation truncates any fractional part(or) it gives the quotient of an integer division.

The modulo division operation products the remainder of an integer division.

All arithmetic operators are binary operators, because they act on two operands, The operators *, /, % will be given the highest priority over + and -.

When equal priority operators are there in an expression, the operators will be evaluated from left to right i.e they follow left to right associativity

Examples :

sum = b + c; sub = b - c; mul = b * c;

div = b / c; rem = b % d;

Example : arithmetic expression : a = b / c * d;

when b = 10, c = 5, d = 3, the value of a = 6.

Here b, c, d are variables and are known as operands.

The symbols *, / are known as operators (Arithmetic operators).sum = b + c; sub = b - c; mul = b * c;

div = b / c; rem = b % d;

Example : arithmetic expression : a = b / c * d;

when b = 10, c = 5, d = 3, the value of a = 6.

Here b, c, d are variables and are known as operands.

Operator |
Meaning |
Examples |
---|---|---|

+ | Addition | 1 + 2 = 3 |

- | Substraction | 3 - 2 = 1 |

* | Multiplication | 2 * 2 = 4 |

/ | Division | 3 / 2 = 1 |

% | ModuloDivision | 10 % 3 = 1 |

- The modulo division operator % cannot be used on floating point data.
- C does not have an operator for exponentiation.
- ANSI C supports unary plus

Arithmetic operations are of the following three types :

- Integer arithmetic
- Real arithmetic
- Mixed mode arithmetic

When both the operands in a single arithmetic expression such as a + b are integers, then the expression is called integer expression, and the operation is called integer arithmetic. Integer arithmetic always yields an integer value. The largest integer value depends on the machine.

For a = 14 and b = 4, we have the following results :

a - b = 10, a + b = 18, a * b = 56

a / b = 3 (decimal part truncated), a % b = 2 (reminder of division)

During integer division, if both the operands are of the same sign, the result is truncated towards zero. If one of them is negative, the direction of truncate is implementation dependent. That is 6 / 7 = 0 and -6 / -7 = 0

But -6 / 7 may be zero or -1 (Machine dependent)

Similarly, during modulo division, the sign of the result is always the sign of the first operand( the dividend). That is

-14 % 3 = -2

-14 % -3 = -2 and 14 % -3 = 2

-14 % -3 = -2 and 14 % -3 = 2

An arithmetic operation involving only real operands is called **Real arithmetic.** A real operand may assume values either in decimal or exponential notation. Since floating point values are rounded to the number of significant digits permissible, the final value is an approximation of the correct result.

If x, y and z are float, then we will have :

x = 6.0 / 7.0 = 0.857143

y = 1.0 / 3.0 = 0.333333

z = -2.0 / 3.0 = -0.666667

y = 1.0 / 3.0 = 0.333333

z = -2.0 / 3.0 = -0.666667

The operator % can not be used with real operands.

The expression 30.0 % 4.0 is invalid expression.

When one of the operands is real and the other is integer, the expression is called a mixed mode arithmetic expression.

It either operand is of the real type, then only real operation is preformed and the result is always a real number. Thus

15 / 10.0 = 1.5 where as 15 / 10 =

Post Article

Upload Youtube Video

CLanguage

Friday, 31 Mar 2017

139

0

0

Popular Post

- Write an algorithm and draw the flowchart to find the largest number among the three numbers?
- Write an algorithm an draw flowchart to find factorial of a number?
- Write an algorithm and draw the flowchart to find whether a given number is even or odd?
- Write an algorithm and draw the flowchart to Swap two integers?
- Write an algorithm an draw the flowchart to compute the average of the three numbers?
- Write an algorithm and draw the flowchart to find the largest number amoug two numbers?
- write a c program to swap two numbers
- How to write a algorithm?
- What is mean by Operator Precedence and Associativity in C Language?
- C Languages Relational Operators

All contents are copyright of their authors