**Interview Questions and Answers on Operators in C Language**

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 !).

4. What is meant by Associativity of Operators?

Associativity indicates in which order two operators of same precedence (priority) executes.

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.

Right associativity of operators is applied when we want to group from right to left and normally used with unary operators.

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.

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.

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.

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.

11. What is the modulus operator?

The modulus operator outputs the remainder of a division. It makes use of the percentage (%) symbol.

12. What are the restrictions of a modulus operator in C?

There is a restriction in C language while using the modulus operator.

There are three types of numerical data types namely integer, float and double. But modulus operator can operate only on integers and

cannot operate on floats or double.

If anyone tries to use the modulus operator on floats then the compiler would display error message as ‘Illegal use of Floating

Point’.

13. 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.

A simple relational expression contains only one relational operator.

14. 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.

15. What are Assignment operators in C language?

The Assignment Operator evaluates an expression on the right of the expression and substitutes it to the value or variable on the left

of the expression.

For example,

x = a + b

Here the value of a + b is evaluated and substituted to the variable x.

In addition, C has a set of shorthand assignment operators of the form.

var oper = exp;

Here var is a variable, exp is an expression and oper is a C binary arithmetic operator. The operator oper = is known as shorthand

assignment operator

16. What are increment and decrement operators in C language?

The increment and decrement operators are one of the unary operators which are very useful in C language. They are extensively used in

for and while loops. The syntax of the operators is

• ++ variable name

• variable name++

• – –variable name

• variable name– –

The increment operator ++ adds the value 1 to the current value of operand and the decrement operator – – subtracts the value 1 from

the current value of operand. ++variable name and variable name++ mean the same thing when they form statements independently, they

behave differently when they are used in expression on the right hand side of an assignment statement.

17. What are conditional or ternary operators in C language?

The conditional operator is also known as ternary operator. It is called ternary operator because it takes three arguments. The

conditional operator evaluates an expression returning a value if that expression is true and different one if the expression is

evaluated as false. It works from left to right.

18. What is the use of bitwise operators in C language?

The smallest element in memory on which is able to operate is called byte; and the programming languages are byte oriented. One of the

c powerful features is a set of bit manipulation operators. The bitwise operator performs the operation on bits (i.e. bit by bit).

Using the bitwise operators we can set / reset / check any bit in the value of the variable.

There are three types of bitwise operator.

• Bitwise AND(&)

• Bitwise OR(|)

• Bitwise Exclusive OR(^)

Bitwise AND operator: The output of logical AND is 1 if both the corresponding bits of operand is 1. If either of bit is 0 or both

bits are 0, the output will be 0. It is a binary operator (works on two operands).

Bitwise OR operator: The output of bitwise OR is 1 if either of the bit is 1 or both the bits are 1.

Bitwise XOR(exclusive OR) operator The output of bitwise XOR operator is 1 if the corresponding bits of two operators are opposite

(i.e., To get corresponding output bit 1; if corresponding bit of first operand is 0 then, corresponding bit of second operand should

be 1 and vice-versa.).

19. What is sizeof () operator?

The operator size of gives the size of the data type or variable in terms of bytes occupied in the memory. The operand may be a

variable, a constant or a data type qualifier.

The size of operator is normally used to determine the lengths of arrays and structures when their sizes are not known to the

programmer. It is also used to allocate memory space dynamically to variables during the execution of the program.

20. What is comma operator?

The comma operator can be used to link related expressions together. A comma-linked list of expressions is evaluated left to right and

value of right most expression is the value of the combined expression.

21. What is an L-value?

An L-value is an expression to which a value can be assigned.

The L-value expression is located on the left side of an assignment statement, whereas an R-value is located on the right side of an

assignment statement. Each assignment statement must have an L-value and an R-value.

The L-value expression must reference a storable variable in memory. It cannot be a constant.

22. What is an R-value?

R-value can be defined as an expression that can be assigned to an L-value. The R-value appears on the right side of an assignment

statement.

Unlike an L-value, an R-value can be a constant or an expression

An assignment statement must have both an L-value and an R-value.

23. What is arrow operator?

In C programming we use arrow operator to access structure member using the pointer variable.

Whenever we declare structure variable then member can be accessed using the dot operator. But when pointer to a structure is used

then arrow operator is used.

24. What is unary operator?

Unary Operators are those operators which operate on 1 operand like/example a++, ++a,--b etc. The letters a, b are called operands and

++, -- are called as Operators.

25. What is binary operator?

A type of operator that works with two operands is known as binary operators.

## 0 comments:

## Post a Comment