Operators in C
Operators in C
Operators in C
SOLIDWORKS
• Many later languages have borrowed syntax/features directly or indirectly from C language.
Like syntax of Java, PHP, JavaScript, and many other languages are mainly based on C
language. C++ is nearly a superset of C language (There are few programs that may compile
in C, but not in C++).
TYPES OF OPERATORS
1) Arithmetic Operators
2) Relational ( Comparison) Operators
3) Logical Operators
4) Assignment Operators
5) Ternary (Conditional) Operator
6) Increment / Decrement Operators
7) Bitwise Operators
ARITHMETIC OPERATORS
1) + Addition
2) - Subtraction
3) * Multiply
4) / Divide
5) % Modulus ( Remainder of Division )
void main() EXAMPLE
{
int x;
x=10+20;
printf ( “%d \n” , x);
x=30-5;
printf ( “%d \n” , x);
x=6*8;
printf ( “%d \n” , x);
x=100/20;
printf ( “%d \n” , x);
x=25%7;
printf ( “%d \n” , x);
}
OUTPUT
RELATIONAL ( COMPARISON)
OPERATORS
1) && And
2) || Or
3) ! Not
ASSIGNMENT OPERATORS
1) =
2) += x += 5 means x = x + 5
3) -= x -= 5 means x = x - 5
4) *= x *= y means x=x*y
5) /= x /= 5 means x = x / 5
6) %= a %= b means a = a % b
EXAMPLE
void main( )
{
int x=100;
x/=5;
printf ( “%d \n” , x);
x*=3;
printf ( “%d \n” , x);
x%=8;
printf ( “%d \n” , x);
}
OUTPUT
TERNARY (CONDITIONAL)
OPERATOR
? :
Syntax:
Condition ? Statement 1 : Statement 2 ;
True False
EXAMPLE
void main()
{
int x=10;
x > 50 ? printf(“Hello”) : printf(“Welcome”);
}
OUTPUT
Hello
INCREMENT / DECREMENT
OPERATORS
++ Increment Operator
-- Decrement Operator
void main()
{
int x=100, y=200;
x++;
y--;
printf( “ %d \n %d” , x , y);
}
OUTPUT
BITWISE OPERATORS