Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +917541905230, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec

Saturday, June 27, 2020

Arithmatic operator in C




Arithmatic Operator in C
By Ahmad Irshad | C Programming Tutorial > Arithmatic operaotrs in C

In C programming, arithmatic operators are used to perform mathematical operations. For example: addition, subtraction, multiplication, division, and modulus.

C supports five arithmetic operators.

OperatorDescription
+Unary plus or binary addition
-Unary minus or binary subtraction
*Multiplication
/Division
%Modulo division (Evaluates remainder)

Unary plus (+) and unary minus (-) operator:

Unary operators required only one operand and used to indicates the number is positive or negative. 

For Example:

  1. a = -10; // a holds -10 (negative)
  2. b = +3.14; // b holds +3.14 (positive)
  3. c = -b; // c holds -(+3.14) => -3.14 (negative)
  4. d = -a; // d holds -(-10) => +10 (positive)

By default, every number is positive. Therefore, use of unary plus operator is optional. Means b = +3.14; is equivalent to b = 3.14;.

Binary arithmatic operators:

Binary arithmatic operators work with two operands. which are used to perform basic arithmatic operation like addition, subtraction, multiplication, division, and modulus (%).

Suppose two integer variables x and y with initial values.
int x=20, y=10;

After performing following binary arithmetic operations.

  1. x + y = 30;
  2. x - y = 10;
  3. x * y = 200;
  4. x / y = 2; // quotient = 2, of integer division
  5. x % y = 0; // Remainder = 0, of integer division

Integer division:

C performs integer division if both operands are integer type. Integer division always evaluates to an integer discarding the fractional part.

For Example:

OperationResultDivision type
5 / 22Integer division
Real division:

C performs real division if any of the two operands are real type (either float or double). Real division evaluates to a real value containing integer as well as fractional part.

For Example:

OperationResultDivision type
10 / 2.05.0Real division
5.0 / 22.5Real division
5 / 2.02.5Real division
5.0 / 2.02.5Real division
Mudulo division %:

Modulo division evaluates remainder after performing division of two numbers. 

1) Modulo division is only possible with integer operands. It causes compilation error with float types.
2) Modulo operator returns sign of the first operand.

For Example:

OperationResult
8 % 20
5 % 32
3 % 73
-3 % 7-3
5 % -21
-8 % -3-2
*******************************
2.5 % 2Error
8 % 2.5Error
5.0 % 2.5Error




Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +966532621401, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec

Help others by sharing this page.

Ahmad Irshad

Author & Editor

I love blogging, teaching, learning computer science and sharing it to others. I've written and develped this site so that students may learn computer science related tutorials eaisly. MCA / MCITP

0 Comments:

Post a Comment

Please don't enter any spam link in the comment box.


Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +966532621401, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec
Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec
Contact Us