Numeric expressions and comparisons Quiz

Test your knowledge on numeric expressions, integer versus floating-point division, modulo operation with negatives, number overflows, underflows, and precision checks. This quiz covers basic concepts and evaluation rules central to programming with numeric data types.

  1. Integer vs Floating-Point Division

    What is the result of the expression 7 / 2 when both 7 and 2 are integers in most programming languages?

    1. 4
    2. 3
    3. 3.5
    4. 2.5
  2. Floating-Point Division

    If x = 10.0 (float) and y = 3 (integer), what is the result of x / y?

    1. 3.0
    2. 3.3333333333333335
    3. 3
    4. 7.0
  3. Modulo With Negative Numbers

    What is the result of -13 % 5 in a language where the sign of the result matches the dividend?

    1. -3
    2. 3
    3. 2
    4. -2
  4. Equality Checks Precision

    Why is directly comparing two floating-point values for equality generally discouraged?

    1. Because comparison operators only work for integers
    2. Because it slows down code
    3. Because integers and floating-point numbers are always stored the same way
    4. Because floating-point arithmetic can introduce small precision errors
  5. Integer Overflow

    Which issue can occur if you add two very large integers that exceed the maximum storable value of the data type?

    1. Modulo error
    2. Precision loss
    3. Overflow
    4. Truncation
  6. Order of Evaluation with Increment

    Given int x = 4; int y = x++; what will y be after this statement?

    1. 4
    2. 3
    3. 6
    4. 5
  7. Floating-Point Underflow

    What could happen if a very small positive floating-point number is divided by a large value?

    1. It may underflow to zero
    2. It will always result in one
    3. It will produce infinity
    4. It will convert to an integer
  8. Modulo for Even and Odd

    What is a common use for the modulo operator (%) in integer arithmetic?

    1. Checking if a number is even or odd
    2. Calculating square roots
    3. Finding averages
    4. Converting types
  9. Increment Prefix vs Postfix

    When using ++x rather than x++, how does the value of x change in an expression?

    1. x is never incremented
    2. x is incremented after its value is used
    3. x is decremented after the current line
    4. x is incremented before its value is used
  10. Precision of Division Results

    In some languages, what happens if you divide 10 by 3 using only integers and assign the result to a floating-point variable?

    1. The division is performed with decimals, resulting in 3.33333
    2. It will always cause an error
    3. The result is NaN
    4. The division yields 3, then it is stored as 3.0