C - Operators Practice Test.3

  1. What is an expression in C?

    A) A statement that performs an action

    B) A combination of variables, operators, and constants that evaluates to a value

    C) A loop construct used for iteration

    D) A function definition

    Answer: B) A combination of variables, operators, and constants that evaluates to a value

  2. Which of the following is NOT a valid C expression?

    A) `x + y`

    B) `5 * 3 - 2`

    C) `int a;`

    D) `x == y`

    Answer: C) `int a;`

  3. In the expression `x = y + 2`, what is the value of `x` if `y` is 5?

    A) 7

    B) 5

    C) 10

    D) It depends on the value of `x`

    Answer: A) 7

  4. What is the result of the expression `7 / 2` in C?

    A) 3.5

    B) 3

    C) 3.0

    D) 4

    Answer: B) 3

  5. Which operator is used for assigning a value to a variable in C?

    A) `+`

    B) `-`

    C) `=`

    D) `==`

    Answer: C) `=`

  6. What is the purpose of parentheses in expressions?

    A) They are used to comment out parts of the expression.

    B) They are used for multiplication.

    C) They specify the order of evaluation.

    D) They indicate bitwise operations.

    Answer: C) They specify the order of evaluation.

  7. Which of the following expressions is equivalent to `x = x + 1` in C?

    A) `x += 1`

    B) `x -= 1`

    C) `x *= 1`

    D) `x /= 1`

    Answer: A) `x += 1`

  8. What is the value of the expression `5 % 2` in C?

    A) 2.5

    B) 2

    C) 1

    D) 0

    Answer: C) 1

  9. In C, what does the `sizeof` operator return?

    A) The size of a variable in bytes

    B) The address of a variable

    C) The value of a variable

    D) The result of a mathematical expression

    Answer: A) The size of a variable in bytes

  10. What is the value of the expression `(x > y) ? x : y` if `x` is 8 and `y` is 10?

    A) 8

    B) 10

    C) 0

    D) 1

    Answer: B) 10

  11. In C, what is the result of the expression `5 + 3 * 2`?

    A) 10

    B) 11

    C) 16

    D) 26

    Answer: B) 11

  12. What is the order of evaluation for the expression `a + b * c` in C?

    A) `a`, `b`, `c`

    B) `b`, `c`, `a`

    C) `c`, `b`, `a`

    D) It depends on the compiler

    Answer: B) `b`, `c`, `a`

  13. In the expression `x = y * 2`, if `y` is 5, what is the value assigned to `x`?

    A) 10

    B) 5

    C) 2

    D) It depends on the previous value of `x`

    Answer: A) 10

  14. What is the result of the expression `10 / 3` in C?

    A) 3

    B) 3.33

    C) 3.0

    D) 3.3333333333...

    Answer: C) 3.0

  15. What is the order of evaluation for the expression `a = b + c - d * e` in C?

    A) `d`, `e`, `b`, `c`, `a`

    B) `b`, `c`, `d`, `e`, `a`

    C) `d`, `e`, `a`, `b`, `c`

    D) It depends on the parentheses

    Answer: A) `d`, `e`, `b`, `c`, `a`

  16. In C, what is the result of the expression `(7 + 3) * 2`?

    A) 14

    B) 20

    C) 10

    D) 26

    Answer: B) 20

  17. Which of the following expressions is evaluated first in C?

    A) Multiplication

    B) Division

    C) Addition

    D) Subtraction

    Answer: A) Multiplication

  18. What is the value of the expression `10 % 3` in C?

    A) 0

    B) 1

    C) 2

    D) 3

    Answer: B) 1

  19. In the expression `x += 3`, what does the `+=` operator do?

    A) Subtracts 3 from `x`

    B) Multiplies `x` by 3

    C) Adds 3 to `x`

    D) Divides `x` by 3

    Answer: C) Adds 3 to `x`

  20. What is the result of the expression `5 + 2 * 3 - 4 / 2` in C?

    A) 6

    B) 7

    C) 5

    D) 8

    Answer: B) 7