Вы находитесь на странице: 1из 5

WORKSHEET-4

COMPUTER SCIENCE (Book-II) Chapter # 9

Worksheet-4 6. Which of the following is a “not equal


to” operator?
CHAPTER-9
A. >=
Data Types Onwards Complete
B. <=
1. The operator which operates on three
C. !=
operands is called:
D. None of the above
A. Unary operator
7. 10 && 8 will evaluate to:
B. Binary operator
A. True
C. Ternary operator
B. False
D. None of the above
C. Both A & B
2. Following are arithmetic operators
except: D. None of the above

A. + 8. The “ x= = 7” will:

B. % A. Assign 7 as value to x
B. Store 7 in x
C. –
C. Check whether 7 is equals to x or not
D. x
D. None of the above
3. Predict the output of the given code:
9. The logical OR operator combines two
int temp = 5%2*3/2; conditions and evaluates to true if:
printf (“%d”, temp); A. Either of condition is true
A. 1
B. 2 B. No condition is true
C. 3 C. Both conditions are true
D. Syntax error D. None of the above
4. 70%5 will result in: 10. x- -; is same as:
A. 0 A. x = x – x;
B. 3.5
B. x = x – 1;
C. 18
D. None of the above C. x - x = 0;

5. The non-zero value is returned only D. x - 1 = x;


when the expression evaluates to: 11. What will be the value of x if?
A. True int x=5*9/3+9
A. 3.5
B. False
B. 24
C. Both A & B
C. 60
D. None of the above
D. None of the above

Your STEP Towards A Brighter Future! 497


COMPUTER SCIENCE (Book-II) Chapter # 9

12. Which of the following logical operator


reverses the result of the evaluated
condition?
A. &&
B. !
C. | |
D. All of the above
13. int x =18 / 4; contents of x will be:
A. 4
B. 0.5
C. 4.5
D. None of the above
14. Adding // before a C statement will:
A. Make it ugly
B. Make it unique
C. Make it comment
D. None of the above
15. All of the given are compound
arithmetic expressions except:
A. x*=10
B. x/=3
C. x!=5
D. x%=2

Your STEP Towards A Brighter Future! 498


COMPUTER SCIENCE (Book-II) Chapter # 9

ANSWER KEY (Worksheet-4) 7. (A) As both operators along && are non-zero
1 C 11 B so it will evaluate to true.
2 D 12 B 8. (C) “= =” is equal to operator which checks
3 A 13 A whether two operands are equal or not
4 A 14 C
while “=” is an assignment operator.
5 A 15 C
6 C 9. (A) If any condition is true, logical OR
7 A operator will evaluate it to true. It is
8 C represented by the || symbol.
9 A 10. (B) x- -; is same as x=x-1;
10 B 11. (B) As * and / have the same precedence so it
ANSWERS EXPLAINED will be evaluated from left to right i.e.
5*9/3+9 => 45/3+9 => 15+9 => 24
1. (C) The ternary operator requires three
operands. 12. (B) NOT logical operator reverses the result of
the evaluated condition i.e. it turns true
2. (D) It seems x is a multiplication operator but
into false and vice versa.
in fact * is used as multiplication operator
in programming. 13. (A) Answer should be 4.5 but as both of the
numbers are integers so the decimal
3. (A)The expression will be evaluated from left
portion is truncated.
to right as all operators have the same
precedence. So the order of evaluation will 14. (C) To add comments we use // or /* */
be:
15. (C) An expression which involves an
5% 2*3/2 => 1*3/2 => 3/2 => 1 arithmetic operator is known as an
4. (A) The modulus operator (%) returns the arithmetic expression. Here the ! is a
remainder of an integral division hence logical NOT operator which results in the
70%5 will result in 0. logical expression.

5. (A) When the condition evaluates to true the


non-zero value is returned and when it
evaluates to false, zero is returned.
6. (C) “Not equal to” operator is a type of
relational operator. Relational operators
are as following:
i) Greater than (>) ii) Less than (<)
iii) Greater than or equal to (>=)
iv) Less than or equal to (<=)
v) Equal to (= =)
vi) Not equal to (!=)

Your STEP Towards A Brighter Future! 499

Вам также может понравиться