OPERATOR
OPERATORS
Generally an operator is a symbol that operates shortens values of variables of same data types and produced a result. An operator operates on variables and perform and action in a program. There are three types of operators as below.
- Unary Operator
- Binary Operator
- Arithmetic Operators
- Relational Operators
- Logical Operators
- Assignment Operators
- Pointers Operators
- Special Operators
- Bitwise Operators
- Ternary Operator
Unary Operator
The operators which have only one operand are called Unary Operator. The Unary Operators are:
- ± : Sign operator
- ++ : Increment operator
- – – : Decrement operator
- & : Address of operator
- * : Value of address
- ~ : Complement operator
Increment and decrement operators are unary operators that add or subtract one from their operand, respectively. The increment operator and decrement operators manifest in to two forms as Postfix and Prefix.
- Post increment and Post decrement:
- C++ : Assign the value and increase the value by 1.
- C– : Assign the value and decrease the value by 1.
[Here C is deem as a variable]
Example: If a=5, b=a++ then b=5 and a=6 , If a=5, b=a– then b=5 and a=4
- Pre increment and Post decrement:
- ++C : Increase the value and then assign that value.
- – –C : Decrease the value and then assign that value.
[Here C is deem as a variable]
Example: If a=5, b=++a then b=6 and a=6, If a=5, b=–a then b=4 and a=4
Binary Operator
In mathematics, a binary operation is a calculation involving two operands, so operator which have two operands are called Binary operator. All arithmetical, relational, assignment, logical and bitwise operators are Binary.
Table 1: List of Binary Operators
Sl. No. | Category | Operator | Operation/ Meaning |
1 | Mathematical | + | Addition |
2 | Mathematical | – | Subtraction |
3 | Mathematical | * | Multiplication |
4 | Mathematical | / | Division |
5 | Mathematical | % | Reminder |
6 | Relational | > | Greater than |
7 | Relational | < | Less than |
8 | Relational | >= | Greater than equal to |
9 | Relational | <= | Less than equal to |
10 | Relational | == | Equal to |
11 | Relational | != | Not equal to |
12 | Bitwise | & | Bitwise And |
13 | Bitwise | | | Bitwise OR |
14 | Bitwise | ^ | Bitwise exclusive OR |
15 | Bitwise | << | Left shift |
16 | Bitwise | >> | Right shift |
17 | Bitwise | ~ | Bitwise complement |
18 | Assignment | += | Addition with assignment |
19 | Assignment | -= | Subtraction with assignment |
20 | Assignment | *= | Multiplication with assignment |
21 | Assignment | /= | Division with assignment |
22 | Assignment | %= | Reminder with assignment |
23 | Logical | && | Logical And |
24 | Logical | || | Logical OR |
25 | Logical | !! | Logical NOT |
Ternary Operator
The operator which have three operands are called Ternary operator. The ternary operator “?:” earns its name because it’s the only operator to take three operands. It is a conditional operator that provides a shorter syntax for the if..then..else statement. The three parts of it’s are Expression, True part and False Part.
Syntax : Condition ? Expression1 : Expression2
Example : x>y ? g=x : g=y;
Or : g=x>y ? x : y;
DATA TYPES IN C
The kind of data that the variable may hold in a programming language is referred to as data types. C provides two types of data:
- Primary or Primitive Data type
- Secondary or Derived Data type
Primary Data type:
TYPE | SIZE (Bits) | Range |
Char or Signed Char | 8 | -128 to 127 |
Unsigned Char | 8 | 0 to 255 |
Int or Signed int | 16 | -32768 to 32767 |
Unsigned int | 16 | 0 to 65535 |
Short int or Signed short int | 8 | -128 to 127 |
Unsigned short int | 8 | 0 to 255 |
Long int or signed long int | 32 | -2147483648 to 2147483647 |
Unsigned long int | 32 | 0 to 4294967295 |
Float | 32 | 3.4 e-38 to 3.4 e+38 |
Double | 64 | 1.7e-308 to 1.7e+308 |
Long Double | 80 | 3.4 e-4932 to 3.4 e+4932 |
Secondary Data type:
- Array
- Structure
- Pointer
- Enum
- Union, etc.
