Skip to main content

Important Introduction to Programming Short Questions

Chapter: 30
Question 1:
What is a synonym in the context of C++ references?
Answer: A synonym in C++ references means that the reference acts as an alternate name for an existing variable.
Chapter: 30
Question 2:
When should you use pointers over references in C++?
Answer: Pointers should be used when you need to manage memory dynamically, perform pointer arithmetic, or when nullability is required.
Chapter: 30
Question 3:
Can you perform arithmetic operations on references?
Answer: No, arithmetic operations cannot be performed on references, unlike pointers.
Chapter: 30
Question 4:
How does passing by reference affect the original variables in a function?
Answer: Passing by reference allows the function to modify the original variables directly since the reference points to the actual memory location of the variables.
Chapter: 30
Question 5:
What is the syntax to declare a function that returns a reference?
Answer: The syntax is datatype& function_name(parameters); for example, int &myfunc() for a function returning a reference to an integer.
Chapter: 30
Question 6:
What are the three ways to pass arguments to a function in C++?
Answer: The three ways are call by value, call by reference using pointers, and call by reference using reference variables.
Chapter: 30
Question 7:
How can you prevent changes to a referenced variable in a function?
Answer: You can prevent changes by declaring the reference as const in the function prototype, ensuring the referenced variable is read-only.
Chapter: 31
Question 8:
What is operator overloading?
Answer: Operator overloading allows the same operator to be used with different implementations depending on the operand types. It enables the use of operators with user-defined types such as classes.
Chapter: 31
Question 9:
Why is operator overloading required?
Answer: Operator overloading is required to enable the use of standard operators with user-defined types, making code more readable and allowing for operations like addition or concatenation with custom classes.
Chapter: 31
Question 10:
Can built-in types be overloaded?
Answer: No, operator overloading cannot be performed for built-in (primitive) types. It is only applicable to user-defined types such as classes.