by Dinesh Thakur Category: Operator

There are five arithmetic operators, +, -, *, *I, *and %, which respectively represent the processes of addition, subtraction, multiplication, division, and modulus. The modulus operator (%) gives the remainder when one integer is divided by another integer. All of the five operators have been described with examples of codes in Table.

It should be noted that each of these operators has a precedence level, that is, priority in operation. If an expression contains operation of multiplication and addition, the multiplication is performed first because it has higher precedence level than that of the addition. Table shows the precedence level of different operators. In many arithmetic operations, the parentheses () are also used. It is generally employed to change the precedence level, that is, priority in operation. The precedence determines when a particular operator will be implemented when there are several operators in a single formula.

The step-by-step operation of a computer on a calculation is illustrated below.

A= 10/2 - 3%2 + (3 + 2) * 5

= 10/2 - 3%2 + 5 * 5

=5-3%2+5*5

=5-1+5*5

= 5 - 1+25

= 4 + 25 = 29

If there are several arithmetic operators of same priority in a line, the operations are done from left to right. This is called associativity. However, the assignment represented by (=) is last to be implemented, and it is implemented from right to left. In the above operation 29 is assigned to A.

The characters are integral constants. Similar to other constants, characters may also be added or subtracted. Program illustrates some arithmetic operations on character variables.

#include <stdio.h>

void main()

{

char ch1,ch2, ch3, ch4,ch5,ch6, ch7 ;

/* chl to ch8 are simply names of variable. Their type is char*/

clrscr();

ch1 = 'A'; /*The value of character A in ASCII code is 65.*/

ch2 = ch1; // assigning value of one to another.

ch3 = ch1 +5 ;

ch4 = ch3 +'2';//here '2' is a character

ch5 = ch3 - 2;

ch6 ='9'*2;

ch7 = '5' + '6';

printf("ch2 = %c,\t ch3 = %c\n", ch2, ch3 );

printf("ch4 = %c,\t ch5 = %c\n", ch4, ch5 );

printf("ch6 = %c,\t ch7 = %c\n", ch6, ch7 );

}

About Dinesh Thakur

Dinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Search Content

Popular Article

#### Define Operator, Operand, and Expression in 'C'

#### Which bitwise operator is suitable for checking whether a particular bit is ON or OFF

#### Define different types of Operators.

#### How does the prefix and postfix operator on expression

#### What is the functionality and restrictions of Modulus Operator

#### What is the difference between ++var and var++

#### Boolean Operators in C

#### What is Precedence of Operators

#### Bitwise Operators in C

#### Composite Assignment Operators in C

#### sizeof() operator in C

#### Relational and Equality Operators

#### Arithmetic Operators in C

#### Logical Operators in C

#### What is Operators in C language?

#### What is Precedence and Associativity of Operators?

#### What is conditional expression operator(ternary operator)?

#### What is Arithmetic operator in C language?

#### Assignment Operator in C

#### Const and volatile Qualifiers in C

Basic Courses

Advance Courses