Understanding Parameter Passing and Side Effects Quiz

Assess your knowledge of parameter passing techniques, reference vs value semantics, and side effects in programming. This quiz covers core concepts including immutability, argument behavior, and function effects.

  1. Identifying Parameter Passing

    In a function where an integer variable is passed and modified inside the function, but the change does not affect the original variable outside, which type of parameter passing is most likely used?

    1. Pass by object
    2. Pass by value
    3. Pass by address
    4. Pass by copy
    5. Pass by reference
  2. Recognizing Side Effects

    If a function changes a global variable when it is called, what programming concept does this illustrate?

    1. Side effect
    2. Pure function
    3. Recursion
    4. Pass by value
    5. Parameter scope
  3. Reference Semantics Example

    Given a function that modifies the contents of a list passed as an argument, and the caller sees the modification, what kind of parameter passing is this?

    1. Pass by copy
    2. Pass by reference
    3. Pass by value
    4. Pass by name
    5. Pass by constant
  4. Understanding Immutability

    Which of the following best describes immutability in programming?

    1. An object's state cannot be changed after its creation
    2. A variable cannot be named the same as another
    3. Parameters are always passed by value
    4. Functions cannot return values
    5. A variable is always local to a function
  5. Predicting Value Changes

    If a string is passed to a function and the function attempts to alter its content, but the original string remains unchanged, why does this most likely occur?

    1. Strings are immutable
    2. Pass by reference was used
    3. The function has no return statement
    4. Parameter overloading
    5. Side effect occurred
  6. Parameter Passing Mechanism

    When a function receives its arguments as copies rather than references to the originals, what is this parameter passing method called?

    1. Pass by lambda
    2. Pass by ref
    3. Pass by value
    4. Pass by class
    5. Pass by event
  7. Recognizing No Side Effects

    Which characteristic indicates that a function has no side effects?

    1. It does not modify any variable or object outside its own scope
    2. It always returns void
    3. It never has parameters
    4. It always uses recursion
    5. It only accepts immutable arguments
  8. Behavior with Reference Types

    In languages where objects are passed by reference, what happens if a function modifies the attributes of an object argument?

    1. The changes are discarded after the function returns
    2. The object is replaced with a new instance
    3. The changes are restricted to numeric attributes
    4. The changes are visible to the caller
    5. The function throws an error automatically
  9. Immutability and Side Effects

    How does using immutable objects help prevent unintended side effects in a program?

    1. They increase memory usage automatically
    2. They prevent all types of errors
    3. They cannot be changed by functions, so accidental modifications do not occur
    4. They require more code to create
    5. They always use pass by value
  10. Recognizing Incorrect Parameter Passing

    Which option is not a common parameter passing technique in programming languages?

    1. Pass by address
    2. Pass by value
    3. Pass by name
    4. Pass by event
    5. Pass by reference