C PROGRAMMING LANGUAGE

PART 1: OPERATORS IN C LANGUAGE


OPERATORS IN C LANGUAGE

An operator is a symbol that operates on a value or a variable. For
example: + is an operator to perform addition.
C has a wide range of operators to perform various operations.
Relational Operators
Logical Operators
Assignment Operator
Decrement and increment
Comma Operator
sizeof Operator

C Arithmetic Operators
An arithmetic operator performs mathematical operations such as addition,
subtraction, multiplication, division etc on numerical values (constants and
variables).
Operator Meaning of Operator
+ addition or unary plus
- subtraction or unary minus
* Multiplication
/ Division

%

remainder after division (modulo division)

C Increment and Decrement Operators
C programming has two operators increment ++ and decrement -- to
change the value of an operand (constant or variable) by 1.
Increment ++ increases the value by 1 whereas decrement -- decreases
the value by 1. These two operators are unary operators, meaning they only
operate on a single operand.

C Assignment Operators
An assignment operator is used for assigning a value to a variable. The most
common assignment operator is =
Operator Example Same as
= a = b a = b
+= a += b a = a+b
-= a -= b a = a-b
*= a *= b a = a*b
/= a /= b a = a/b
%= a %= b a = a%b
C Relational Operators
A relational operator checks the relationship between two operands. If the
relation is true, it returns 1; if the relation is false, it returns value 0.
Relational operators are used in decision making and loops.

Operator Meaning of Operator Example

== Equal to 5 == 3 is evaluated to 0

> Greater than 5 > 3 is evaluated to 1

< Less than 5 < 3 is evaluated to 0

!= Not equal to 5 != 3 is evaluated to 1

>= Greater than or equal to 5 >= 3 is evaluated to 1

<= Less than or equal to 5 <= 3 is evaluated to 0
C Logical Operators
An expression containing logical operator returns either 0 or 1 depending
upon whether expression results true or false. Logical operators are
commonly used in decision making in C programming.
Operator Meaning Example

&& Logical AND. True only if all operands are

true

If c = 5 and d = 2 then, expression ((c==5) && (d>5))
equals to 0.

|| Logical OR. True only if either one

operand is true

If c = 5 and d = 2 then, expression ((c==5) || (d>5))
equals to 1.

! Logical NOT. 
True only if the operand is 0 If c = 5 then, expression !(c==5) equals to 0.
Comma Operator
Comma operators are used to link related expressions together. For example:

int a, c = 5, d;

The sizeof operator
The sizeof is a unary operator that returns the size of data (constants,
variables, array, structure, etc).

Comments

Popular posts from this blog

Exporting HTML Page into PDF In Django