Operators of C programming Language


What is Operator?

An operator in programming is a symbol that tells the computer to perform a specific mathematical, relational, or logical operation and produce a final result.


What is operand?

An operand in programming is used to describe any object that can being manipulated. Typically, operands are the data on which operators such as addition or subtraction perform their actions. They can be constants, variables, or expressions, representing values in calculations or other operations.

There are some operators in C programming language.

Binary Operators

Unary Operators

Thernory Operators

Arithmetic operators

Increment, decrement operators

Conditional Operator

Logical Operators

Type cast operator

 

Relational Operators

Sizeof operator

 

Bitwise Operators

 

 

Assignment Operators

 

 

Comma operators

 

 



Arithmetic Operators;

Operator

Description

A+B

Adds A with B

A-B

Subtracts B from A

A*B

Multiplies A by B

A/B

Divides A by B

I%J

Gives the remainder of I divided by J

  

Logical Operators;

Operator

Description

A && B

If one value is 0 the answer is 0

A||B

If one value is 1 the answer is 1

!A

If the value is 0 answer is 1 either value is 1 answer is  0


Relational Operators;

Operator

Description

A < B

The value of A is less than value of  B

A <= B

The value of A is less than or equal to value of  B

A > B

The value of A is greater than value of B

A >= B

The value of A is greater than or equal to value of B

A == B

The value of A is equal to value of B

A != B

The value of A is not equal to value of B



Bitwise Operators;

Operator

Description

A & B

Bitwise form of A AND B

A | B

Bitwise form of A OR B

A ^ B

Bitwise form of A XOR B

~ A  

Bitwise complement of A

A << n

Shifts A to the left n bits

A >> n

Shift A to the right n bits



Eg: A=70 and B = 20

A= 0100 0110
B= 0001 0100

Find,
1.  A&B = 0000 0100
2.  A| B = 0101 0110
3.  A ^ B = 0101 0010
4.  ~A = 1011 1001
5.  A<< 2 =  0001 0001 1000 = 280
6.  A >> 2 = 0001 0001 = 17

Increment and Decrement Operators;

Operator

Description

++A

increments A and then uses its value as the value of the expression

A++

uses A as the value of the expression and then increments A

-- A

Decrements A and then uses its value as the value of the expression

A--

Uses A as the value of the expression and then decrement A



Assignment Operators;

Operator

Expression

Description

=

X = Y

Assign Y value to X

+=

X =+ Y

X = X + Y

-=

X - = Y

X = X - Y

*=

X *= Y

X = X* Y

!=

X /= Y

X = X /  Y

%=

X %= Y

X = X % Y


Size of Operators;

sizeof(type) : it returns the number of bytes needed to contain a value of the specified type.
Eg: sizeof A : has as its value the number of bytes required to hold the result of the evaluation of A.

Comma Operator;

The comma operator is used to link the related expressions together.
A comma operator linked expression is evaluated from left to right and the value of the right most expression is the value of the combined expression.
Eg: x = (a=2,b=4,a+b)  

Arithmetic Operator;

Arithmetic expression in c is a combination of variables, constants and operators written in a proper syntax.
Eg:  1>2+3&&4

Operator precedence and Associativity;

When an expression contains multiple operators, the precedence of the operators controls the order in which the individual operators are evaluated.

A higher precedence operator is evaluated before a lower precedence operator.

Eg: 
(3> 4 + 5 && 5)
This expression is equivalent to:
((3 > (4 + 5)) && 5)
(4 + 5) executes first resulting into 9 then, first part of the expression (3 > 9) executes resulting into 0 (false) then, (0 && 5) executes resulting into 0 (false).

These are the basic operators in C programming. I hope you understand that  what can perform in operators in C programming.

In next lesson we will discuss operators with some practical.

-Team CodeQuasar-

Post a Comment

Previous Post Next Post