Академический Документы
Профессиональный Документы
Культура Документы
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;
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.