C Foundation

What is C? C Compiler Installation C Extensions C Compiler C Interpreter C Program Structure

C Basics

C Keywords C Data Types C Identifiers C Variables C Constant C Escape Sequences C Constant and Volatile C Typecast

Operators

What is Operator C Comma Operator C Arithmetic Operators C Relational Operators C Logical Operators C Bitwise Operators C Conditional Operators C : : Operator C Operator Priority

Basic IO's

Basic IO's C Formatted Functions C Unformatted Functions C Common Functions

Control Statements

What is Control Statement C if Statement C if else Statement C Nested if Statement C Else if Statement C Break Statement C Continue Statement C Switch Statement C Goto Statement

Looping

What is Control Loop C for Loop C Nested for Loop C while Loop C Nested while Loop C do while Loop C Nested do while loop

Functions

What is Function C User Defined Functions C Recursion C Passing Parameters

Scope

Scope C Local Scope C Global Scope

Storage Classes

What is Storage Class C Auto C Extern C Static C Register

Array

What is Array C One Dimensional Array C Two Dimensional Array C Multi Dimensional Array C Arrays Of Strings

String

What is String C String Functions

Pointer

What is Pointer C Pointers Arithmetic C Pointer to Pointer C Pointers and Arrays C Pointers and Strings C Pointer to Functions Void Pointers Null Pointers C Null and Void Pointer

Structure

What is Structure C Struct within Struct C Array within Structure C Pointer to Structure C Structure and Function C Enum C Bitfield Structure C Type def

Union

What is Union

Files

What is File C read a file C write a file C File Handling C Error Handling C Low Level Disk I/O C Other file functions

Memory Allocation

What is Memory Allocation C Malloc() C Calloc() C Free() C Realloc() C Coreleft()

C Reference

All ASCII Code Basic C Questions

C Interview

C Interview Sets All Star Patterns All Number Patterns All Alphabet Patterns All Series Patterns
The ones who are crazy enough to think they can change the world are the ones who do.
- Steve Jobs

Arithmetic Operators


What is Arithmetic Operators

Arithmetic operators can be used to perform arithmetic operations such as Addition, Subtraction, Multiplication and Division. Arithmetic operators are most commonly used operators in computer programming languages. The operands involved in arithmetic operations must represent numerical value. Thus, the operands can be an integer type, floating point types, double and char(In C, characters represent numerical value according to ASCII table). Arithmetic operators can be divided into  3  types, they are

C Arithmetic Operators
  • Unary Operator
  • Binary Operator
  • Ternary Operator

Classifications of Arithmetic Operators

C Arithmetic Operators

Binary Operator in C

Binary operators are act upon a two operands to produce a new value.

Operator Description Example
+ Addition 1 + 2 = 3
- Subtraction 2 - 1 = 1
* multiplication 2 * 3 = 6
/ Division 6 / 3 = 2
% Modular Division 5 % 2 = 1 (remainder)

Binary Operators - C Program

In this program, we make use of several Binary Operators.

  • + is a binary operator, which is used to sum two operands to yield a resultant value.
  • - is a binary operator, which is used to subtract two operands to yield a resultant value.
  • * is a binary operator, which is used to multiply two operands to yield a resultant value.
  • / is a binary operator, which is used to divide two operands to yield a resultant value.
  • % is a binary operator, which is used to find the remainder of two operands when divided.
binaryoperators.c
#include <stdio.h> //header file section
int main() //main section
{
int a = 5;
int b = 2;
int l = a + b;
int m = a - b;
int n = a * b;
int o = a / b;
int p = a % b;
printf("Addition of a and b = %d ", l);
printf("\nSubtraction of a and b = %d ", m);
printf("\nMultiplication of a and b = %d ", n);
printf("\nDivision of a and b = %d ", o);
printf("\nRemainder of a and b = %d ", p);
return 0;
}
  • Addition of a and b = 7
  • Subtraction of a and b = 3
  • Multiplication of a and b = 10
  • Division of a and b = 2
  • Remainder of a and b = 1

Unary Operators in C

Unary operators are act upon a single operand to produce a new value.

Operator Description Example
- Minus Operator int x = -5;
int y = -x;
++ Increment Operator int a = 2;
a = ++a;
-- Decrement Operator int a = 2
a = --a;
& Address Operator int n = 10;
a = &n;
sizeof Gives the size of operator int x = 5;
sizeof(x);

Unary operator - C Program

Let we make use of minus Unary operator and have fun

unaryoperators.c
#include <stdio.h> //header file section
int main() //main section
{
int x = -5;
int y = -x;
printf("The value of x = %d \nThe value of y = %d ",x, y);
return 0;
}
  • The value of x = - 5
  • The value of y = 5

Note:

'-' operator multiplies minus with a value in variable 'x'.

Increment Operator - C Program

Let we make use of Increment Unary operator and have fun

incrementoperator.c
#include <stdio.h> //header file section
int main() //main section
{
int a = 2;
printf("The value of a = %d ", a);
a = ++a;
printf("\nThe value of a = %d ", a);
return 0;
}
  • The value of a = 2
  • The value of a = 3

Note:

An increment operator ++ followed by a variable 'a' will be incremented immediately to the value 3.

Purpose of increment operator

The vital purpose of increment Unary Operator is to add one to their operand.

Decrement Operator - C Program

Let we make use of Decrement Unary operator and have fun

decrementoperator.c
#include <stdio.h> //header file section
int main() //main section
{
int a = 2;
printf("The value of a = %d ",a);
a = --a;
printf("\nThe value of a = %d ",a);
return 0;
}
  • The value of a = 2
  • The value of a = 1

Note:

An decrement operator -- followed by a variable 'a' will be decremented immediately to the value 1.

Purpose of Decrement operator

The vital purpose of Decrement Unary operator is to reduce or subtract one to their operand.

Address Operator(&) - C Program

Let we make use of Address(&) Unary operator and have fun

addressoperator.c
#include <stdio.h> //header file section
int main()
{
int n = 10;
printf("The value of n = %d ",n);
printf("\nAddress of n = %u ",&n);
return 0;
}
  • The value of n = 10
  • Address of n = 2293436

Note:

Memory location for a data can be find out with & operator followed by its variable name. Addresses may differs with respect to memory management architecture of an operating system.

Where address operator get used

While the programmer plays with pointer, the address operator is the one which is most frequenty get used.

sizeof() Operator - C Program

Let we make use of sizeof() Unary operator and have fun

sizeofoperator.c
#include <stdio.h>
int main()
{
int x = 5;
float y = 10;
printf("sizeof (x) = %d \nsizeof (y) = %d ",sizeof(x), sizeof(y));
return 0;
}
  • sizeof (x) = 2
  • sizeof (y) = 4

Note:

Here, the variables declared and initialized as x and y. The variable x is an integer and y is a float data type. Using sizeof() operator, we can identified the size of the variable.

Where sizeof() operator get used

While the programmer plays with dynamic memory allocation, the sizeof() operator is the one which is most frequenty get used.

Report Us

We may make mistakes(spelling, program bug, typing mistake and etc.), So we have this container to collect mistakes. We highly respect your findings.

Report