Showing posts with label C Operators - Arithmetic. Show all posts
Showing posts with label C Operators - Arithmetic. Show all posts

Tuesday, January 26, 2016

Arithmetic Operators

Arithmetic operators are used to perform basic mathematical operations like addition, subtraction, multiplication and division. There are five arithmetic operators available in C (+, -, *, /, %). All arithmetic operators are binary operators, ie; they operate on two operands to produce the result.
The table below lists the arithmetic operators
OperatorNameDescriptionExample
+Addition Operator'+' Operator adds two values. This operator works on integer, float and character variables.20 + 10return 20
-Subtraction Operator'-' Operator produces a result after subtracting two values. It also works on integer, float, character variables.20 - 10returns 10
*Multiplication Operator'*' Operator produces result after multiplication of operands.20 * 10returns 200
/Division Operator'/' Operator produces result of division of first operand by second.20 / 10returns 2
&Modulus Operator'%' Operator generates the remainder after integer division.25 % 10returns 5

Monday, January 25, 2016

C Operators - Arithmetic, Assignment, Relational and Logical

Operator Basics

Operators in C language are symbols which tells the compiler to perform some mathematical calculations or logical operations (we will look at in a while) on the variables and constants. For example, consider the mathematical operation "10 + 2 - a". Here '+' and '-' are called operators and the values on which operators work ('10', '2', and 'a') are known as operands. C programming language has wide variety of operators which are categorised into different groups based on the type of operations they perform.

Operator Arity

Arity implies the number of operands the operator is defined to work on. Based on that we have operators of following articles
ArityDescription
Unary OperatorOperates on single operand.
Binary OperatorOperates on two operands, For example: '/' (used for division).
Ternary OperatorOperates on three operands. Example : conditional operator (we will discuss about it in this chapter).
n-ary OperatorOperators that operate on more than 3 operands.