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.
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?
- Pass by object
- Pass by value
- Pass by address
- Pass by copy
- Pass by reference
Recognizing Side Effects
If a function changes a global variable when it is called, what programming concept does this illustrate?
- Side effect
- Pure function
- Recursion
- Pass by value
- Parameter scope
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?
- Pass by copy
- Pass by reference
- Pass by value
- Pass by name
- Pass by constant
Understanding Immutability
Which of the following best describes immutability in programming?
- An object's state cannot be changed after its creation
- A variable cannot be named the same as another
- Parameters are always passed by value
- Functions cannot return values
- A variable is always local to a function
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?
- Strings are immutable
- Pass by reference was used
- The function has no return statement
- Parameter overloading
- Side effect occurred
Parameter Passing Mechanism
When a function receives its arguments as copies rather than references to the originals, what is this parameter passing method called?
- Pass by lambda
- Pass by ref
- Pass by value
- Pass by class
- Pass by event
Recognizing No Side Effects
Which characteristic indicates that a function has no side effects?
- It does not modify any variable or object outside its own scope
- It always returns void
- It never has parameters
- It always uses recursion
- It only accepts immutable arguments
Behavior with Reference Types
In languages where objects are passed by reference, what happens if a function modifies the attributes of an object argument?
- The changes are discarded after the function returns
- The object is replaced with a new instance
- The changes are restricted to numeric attributes
- The changes are visible to the caller
- The function throws an error automatically
Immutability and Side Effects
How does using immutable objects help prevent unintended side effects in a program?
- They increase memory usage automatically
- They prevent all types of errors
- They cannot be changed by functions, so accidental modifications do not occur
- They require more code to create
- They always use pass by value
Recognizing Incorrect Parameter Passing
Which option is not a common parameter passing technique in programming languages?
- Pass by address
- Pass by value
- Pass by name
- Pass by event
- Pass by reference