Thursday, 7 June 2018

Precedence of operator

MCQ

1. Which of the following is the correct order of evaluation for the below expression?
z = x + y * z / 4 % 2 – 1
A) * / % + - =
B) = * / % + -
C) / * % - + =
D) * % / - + =

2.  If a=8, b=3 and c=-5 are integers, then value of a*b/c is
 A) -4
 B) -2.8
 C) +2.8
 D) +3

3.  In which order do the Relational, Arithmetic, Logical and Assignment operators get evaluated in C? 
A) Arithmetic, Relational, Logical, Assignment
 B) Relational, Logical, Arithmetic, Assignment
C) Logical, Relational, Arithmetic, Assignment
 D) Assignment, Arithmetic, Relational, Logical


 4  ‘C’ expression contains relational, assignment and arithmetic operators. There are no parentheses used. They will be evaluated in which of the following order
A)  Assignment Relational Arithmetic
B)  Arithmetic Relational Assignment
C)   Relational Arithmetic Assignment


D)   Assignment Arithmetic Relational

int z, x=5, y=-10, a=4, b=2; z=x++ - --y * b / a;
  What will be the final value of z?
A) 5
B) 6
C) 10
D) 11


64. Precedence is used
A) To determine which operator evaluated first from left to right.
B) To determine the level of an operator in a program.
C) To determine how an expression involving more than one operator is evaluated.
D) To check the expression is valid or not.

True/False
3.     Two different operators would always have different associativity.
1.           The associativity of operator ! is from left to right.
8.            The precedence of arithmetic operators is (from highest to lowest) %, *, /, +, –

9.  We need to recompile the program before executing it even if there is no change in the source code
10.  In the expression a=b=5 the order of Assignment is NOT decided by Associativity of operators.

23.     Two different operators would always have different associativity.

Question:

1. Evaluate the following expressions, indicating which ones are true or false. 
1. 10 = = 9 + 1 
2. 10 && 8 
3. 8 || 0 4. 0 && 0 
5. Let X = 10 and Y=9; 
X >= 8 && Y <= X

2. Evaluate the following expression and show the hierarchy of operations: (2 + 4)/3 + 2 % 3 * 2 – 5

No comments:

Post a Comment

ch-12 File Handling

Mcq 1. What does fp point to in the program?   #include<stdio.h> int main() {   FILE *fp;   fp=fopen("trial",...