Professional Documents
Culture Documents
Arithmetic
S.no Operation Example
Operators
1 + Addition A+B
2 – Subtraction A-B
3 * multiplication A*B
4 / Division A/B
5 % Modulus A%B
Example for C arithmetic operators:
Simple 10 is assigned to
assignment = sum = 10
operator variable sum
This is same as
+= sum += 10
sum = sum + 10
This is same as
-= sum -= 10 sum = sum – 10
This is same as
*= sum *= 10 sum = sum * 10
This is same as
&= sum&=10 sum = sum & 10
x is greater than
3 >= x >= y
or equal to y
x is less than or
4 <= x <= y
equal to y
5 == x == y x is equal to y
6 != x != y x is not equal to y
Logical operators in C:
S.no Operators Name Example Description
2 | Bitwise OR
3 ~ Bitwise NOT
4 ^ XOR
• Syntax:
• Increment operator: ++var_name; (or) var_name++;
Decrement operator: - -var_name; (or) var_name - -;
• Example:
• Increment operator : ++ i ; i ++ ;
Decrement operator : – – i ; i – – ;
C – Increment/decrement Operators
S.no Operator type Operator Description
#include <stdio.h>
#include <limits.h>
int main()
{
int a;
char b;
float c;
double d;
printf("Storage size for int data type:%d \n",sizeof(a));
printf("Storage size for char data type:%d \n",sizeof(b));
printf("Storage size for float data type:%d \n",sizeof(c));
printf("Storage size for double data type:%d\n",sizeof(d));
return 0;
}
Example program for sizeof() operator in C:
Output:
Storage size for int data type:2
Storage size for char data type:1
Storage size for float data type:4
Storage size for double data type:8
C - Type Casting
• Type casting is a way to convert a variable from one data type to
another data type. For example, if you want to store a 'long' value into
a simple integer then you can type cast 'long' to 'int'.
• You can convert the values from one type to another explicitly using
the cast operator as follows −
• (type_name) expression
EXAMPLE
#include <stdio.h>
main()
{
int sum = 17, count = 5;
double mean;
mean = (double) sum / count;
printf("Value of mean : %f\n", mean );
}
OUTPUT
• Value of mean : 3.400000
• It should be noted here that the cast operator
has precedence over division, so the value of
sum is first converted to type double and
finally it gets divided by count yielding a
double value.