# C Language Questions on Operators

C Language Questions on Operators

1. What is an Operator?
An operator is a symbol which helps the user to command the computer to do a certain mathematical or logical manipulations. Operators are used in C language program to operate on data and variables.

2. What are the different types of Operators in C language?

C has a rich set of operators which can be classified as,
•    Arithmetic operators
•    Relational Operators
•    Logical Operators
•    Assignment Operators
•    Increments and Decrement Operators
•    Conditional Operators
•    Bitwise Operators

3. What is meant by Precedence of operators?

If more than one operator is involved in an expression then, C language has predefined rule of priority of operators. This rule of priority of operators is called operator precedence.
In C, precedence of arithmetic operators(*,%,/,+,-) is higher than relational operators(==,!=,>,<,>=,<=) and precedence of relational operator is higher than logical operators(&&, || and !). Suppose an expression: (a>b+c&&d) This expression is equivalent to: ((a> (b+c)) &&d) i.e., (b+c) executes first then, (a> (b+c)) executes then, (a> (b+c)) &&d) executes.

4. What is meant by Associativity of Operators?

Associativity indicates in which order two operators of same precedence (priority) executes. Let us suppose an expression:
a==b! =c
Here, operators == and! = have same precedence. The associativity of both == and! = is left to right, i.e., the expression in left is executed first and execution take pale towards right. Thus, a==b! =c equivalent to:
(a==b)! =c
The associativity of operators can be of two types:
•    Left associativity
•    Right associativity
Left associativity of operators is generally applied to binary operators and it is used when we want to group the expression from left to right. For example,
a*b+c can be written as (a*b) +c
Right associativity of operators is applied when we want to group from right to left and normally used with unary operators. For example,
-+i can be written as – (+i)

5. Define Operand?

An operand is the part of a computer instruction that specifies data that is to be operating on or manipulated and, by extension, the data itself. Basically, a computer instruction describes an operation (add, subtract, and so forth) and the operand or operands on which the operation is to be performed.

6. Define Expression?

An expression is a statement that states an operation on data. Suppose for example in a mathematical expression like (a+b-c), we can notice that we are performing addition and subtraction on a, b & c collectively. So the addition and subtraction operations are done by + and – operators and that whole statement is known as an expression.

7. What are Arithmetic operators in C language?

The arithmetic operators are used for addition, subtraction, multiplication, division, modulus etc. These are very basic mathematical operations that are very usually required in our programs. Almost all the symbols required to represent them are similar to normal mathematical notations with slight difference. There are 5 different types of arithmetic operators in C language
–   For performing Subtraction
/   For performing Division
*   For performing Multiplication
%   modulo for finding remainder in division operation

8. Define Integer arithmetic operator in C language?

When an arithmetic operation is performed on two whole numbers or integers than such an operation is called as integer arithmetic. It always gives an integer as the result. Let x = 27 and y = 5 be 2 integer numbers. Then the integer operation leads to the following results.
x + y = 32
x – y = 22
x * y = 115
x % y = 2
x / y = 5
In integer division the fractional part is truncated.

9. Define Floating point arithmetic in C language?

When an arithmetic operation is preformed on two real numbers or fraction numbers such an operation is called floating point arithmetic. The floating point results can be truncated according to the properties requirement. The remainder operator is not applicable for floating point arithmetic operands.
Let x = 14.0 and y = 4.0 then
x + y = 18.0
x – y = 10.0
x * y = 56.0
x / y = 3.50

10. Define mixed mode arithmetic in C language?

When one of the operand is real and other is an integer and if the arithmetic operation is carried out on these 2 operands then it is called as mixed mode arithmetic. If anyone operand is of real type then the result will always be real thus 15/10.0 = 1.5

11. What are Relational operators in C language?

Relational operators are basically used in conditional and looping statements. They check for relation between variables or between variables and constants. After they are used, they return 0 if the result is false and return 1 if the result is true. The different relational operators are as follows,
<: is less than
<=: is less than or equal to
>: is greater than
>=: is greater than or equal to
==: is equal to
!=: is not equal to
It is required to compare the marks of 2 students, salary of 2 persons; we can compare those using relational operators.
A simple relational expression contains only one relational operator and takes the following form.
exp1 relational operator exp2
Where exp1 and exp2 are expressions, which may be simple constants, variables or combination of them. Given below is a list of examples of relational expressions and evaluated values.
6.5 <= 25 TRUE
-65 > 0 FALSE
10 < 7 + 5 TRUE

12. What are Logical operators in C language?

Sometimes we must have passed through logic gates like AND, OR, NOT. Similarly in C we can make use of logical operators similar to the operation of And, Or, Not. Logical operators mainly work with the values 0 & 1. Basically in a C program, any non- zero value is treated as true and zero value is treated as false. C has the following logical operators; they compare or evaluate logical and relational expressions.
&&: Logical AND
||: Logical OR
! : Logical NOT
The logical NOT operator basically changes the value for m 0 to 1 and vice versa. The logical AND operator returns a true value only if both the operands have a true value that use the AND operator where as the logical OR operator returns a true value whenever at least one of the operand has a true value that uses it.
Example for logical AND:
a > b && x = = 10
The expression to the left is a > b and that on the right is x == 10 the whole expression is true only if both expressions are true i.e., if a is greater than b and x is equal to 10.
Example for logical OR:
a < m || a < n
The expression evaluates to true if any one of them is true or if both of them are true. It evaluates to true if a is less than either m or n and when a is less than both m and n.
Example for logical NOT:
! (x >= y) the NOT expression evaluates to true only if the value of x is neither greater than or equal to y

0