Ans. : Operator : An operator is a symbol that tells the computer to perform certain mathematical and logical manipulations. Operators are used in programs to manipulate data and variables. Such as, ++, --, <, > etc.
Categories of operators : C operators can be classified into a number of categories. They are as follows,
1) Arithmetic operators. | 2) Relational operators. |
3) Logical operators. | 4) Assignment operators. |
5) Increment and decrement operators. | 6) Conditional operators. |
7) Bitwise operators. | 8) Special operators. |
Qus. 02: Write down about different operators.
Ans. : (1) Arithmetic operators : The arithmetic operators are +, -, *, /. They work the same way as they do in other languages. There are three types of arithmetic operators.
(a) Integer arithmetic : Here operands are integer. For a=14 and b=4,
a+b=18 a/b=3(decimal part) a%b=2(remainder of division)
(b) Real arithmetic : Here, operands are only real number. Such as, if a=6.0 and b=7.0 then a/b=0.857143
(c)Mixed model arithmetic : Here, one operand is real and another is integer. Such as, 15/10.0=1.5
Whereas, 15/10=1
(2) Relational operators : The operators which are used to compare two numbers and take decision depending on their relation are called relational operators. Some relational operators are
Operator | Meaning |
< | Is less than |
<= | Is less than or equal |
> | Is greater than |
>= | Is greater than or equal |
== | Is equal to |
!= | Is not equal to |
(3) Logical operators : Operators which are used to combine two or more relational expressions are known as logical operators. There are three logical operators. They are,
&& meaning logical AND
|| meaning logical OR
! meaning logical NOT
(4) Assignment operators : Operators which are used to assign the result of an expression to a variable are known as assignment operators.
Consider an example, x += (y+1)
The operator += means ‘add y+1 to x’ or ‘increment x by y+1’. For y=2, the above statement results, x += 3, that is (x = x + 3)
(5) Increment and decrement operators : C allows two very useful operators not generally found in other languages. These are the increment and decrement operators, respectively ++ and --. The operator ++ adds 1 to the operand, while -- subtracts 1.
(6)Conditional operators : A ternary operator pair “ ? : ” is available in C to construct conditional expressions of the form exp1?exp2:exp3. The operator works as follows, exp1 is evaluated first. If it is nonzero (true) then the expression exp2 is evaluated and becomes the value of the expression. If exp1 is false, then exp3 is evaluated and becomes the value of the expression. For example, consider the following statements,
a=10;
b=15;
x=(a>b)?a:b;
In this example x will be assigned the value of b.
(7) Bitwise operators : Operators which are used to manipulate data at their bit level are known as bitwise operators. Bitwise operators and their meanings are given below,
Operator | Meaning |
& | Bitwise AND |
| | Bitwise OR |
^ | Bitwise exclusive OR |
<< | Shift left |
>> | Shift right |
(8) Special operators : C supports some special operators of interest such as comma operator, sizeof operator, pointer operators (& and *) and member selection operators (. And ->).
Qus. 03: Write down the rules for ++ and -- operators.
Ans. : Rules for ++ and – operators :
i) Increment (++) and decrement (--) operators are unary operators and they require variable as their operands.
ii) When postfix ++ (or --) is used with a variable in an expression, the expression is evaluated first using the original value of the variable and then the variable is incremented (or decremented) by one.
iii) When prefix ++ (or --) is used in an expression, the variable is incremented (or decremented) first and then the expression is evaluated using the new value of the variable.
The precedence and associatively of ++ and --operators are the same as those of unary + and unary -.ক্রেডিট : তন্ময় চক্রবর্তী
1 comments:
Well, you have mentioned the credit. Thats ok, but you could have told once that you are about to copy all my notes here as a book.
Its not a book, its my notes on C programming based on the book of C programming by E. Balaguruswamy.
Ok. Bye.
01. Overview of C
02. Constants, Variables & Data Types
03. Operators & Expressions
04. Managing I/O Operations
05. Decision Making & Branching
06. Decision Making & Looping
07. Arrays
08. User Defined Functions