Important Introduction to Programming Short Questions
Chapter: 25
Question 1:
What is a potential disadvantage of using inline functions in C++?
Answer:
A disadvantage of inline functions is that if the function is large and called multiple times, it can significantly increase the size of the compiled code.
Chapter: 25
Question 2:
How do inline functions differ from macros in C++?
Answer:
Inline functions, unlike macros, are type-checked by the compiler, do not have side effects, and are generally safer to use because they behave like regular functions.
Chapter: 25
Question 3:
What is function overloading in C++?
Answer:
Function overloading in C++ is the ability to use the same function name to perform different tasks depending on the type or number of arguments passed to it.
Chapter: 25
Question 4:
Give an example of function overloading in C++.
Answer:
An example is overloading the function for calculating square roots: one function could handle int types, and another could handle double types.
Chapter: 25
Question 5:
What does the stream insertion operator (<<) do in C++?
Answer:
The stream insertion operator (<<) is used with cout to print data of various types to the console, and it is overloaded to handle different data types.
Chapter: 25
Question 6:
Why is it important to follow a consistent variable declaration style in C++?
Answer:
Following a consistent variable declaration style enhances code readability and maintainability, making it easier to understand and debug the code.
Chapter: 26
Question 7:
What is a class in programming?
Answer:
A class is a user-defined data type that includes both data members and functions (methods) to manipulate that data.
Chapter: 26
Question 8:
What are member functions in a class?
Answer:
Member functions, also called methods, are functions defined within a class that manipulate the class's data members.
Chapter: 26
Question 9:
What are instances of a class called?
Answer:
Instances of a class are called objects.
Chapter: 26
Question 10:
How is a class different from a structure?
Answer:
In a class, data members are private by default, whereas in a structure, they are public.