Fundamentals of Computer Programming - Old Questions
2. What are the different types of operators available in C?Explain.
An operator is a symbol that operates on single or multiple data items. It is used in program to perform certain mathematical or logical manipulations. E.g. In a simple expression 2+3, the symbol “+” is called an operator which operates on two data items 2 and 3.
C operators can be classified into following types:
1. Arithmetic Operators
Arithmetic operators are used to perform arithmetic operations. There are five arithmetic operators:
2. Relational Operators
- Relational operators are used to compare two operands and taking decisions based on their relation.
- Result of relational expression is either True(1) or False(0).
- Relational operators are used in decision making and loops.
- Relational operators are:
3. Logical Operators
- Logical operators are used to compare logical and relational expression.
- The operands of logical operators must be either Boolean value (1 or 0) or expression that produces Boolean value.
- The output of these operators is always 0 (flase) or 1 (true).
The logical operators are:
4. Assignment Operator
- Assignment operators are used to assign the result of an expression to a variable.
- The mostly used assignment operator is ‘=’.
- C also supports shorthand assignment operators which simplify operation with assignment.
5. Increment and Decrement Operators
- Increment operator is used to increase the value of an operand by 1.
- Decrement operator is used to decrease the value of an operand by 1.
6. Conditional Operator (Ternary Operator)
- It takes three arguments.
- Conditional operators return one value if condition is true and returns another value if condition is false.
Syntax: (condition) ? value_if_true : value_if_false
etc.