Object Oriented Programming · Unit 5
Function Features and Inline Functions
Exam-focused notes for Function Features and Inline Functions (Object Oriented Programming, BIT153): what the TU syllabus asks and how it has actually been tested, with 9 solved past questions from this unit.
What this unit covers
- Default arguments
- Function overloading
- Inline functions: advantages and disadvantages
- Friend functions
- Friend classes
- Member functions defined outside class
Default arguments
Explain default arguments and inline functions in C++ with suitable examples. [5]
--- Definition: Default arguments are values provided in a function declaration that are automatically used when the caller does not supply a corresponding argument. They allow a function to be called with fewer arguments than it is defined to accept. Rules...
Full solved answer →In which case default argument is used? Describe with an example. [5]
A default argument is used when a function is called without providing a value for one or more parameters. If the caller omits an argument, the compiler automatically substitutes the default value specified in the function declaration/definition. 1. When a ...
Full solved answer →What is meant by default argument? Explain with suitable example. [5]
A default argument is a value provided in a function declaration that is automatically used by the compiler if the caller does not supply a corresponding argument in the function call. It allows a function to be called with fewer arguments than it is define...
Full solved answer →Friend functions
Explain friend function and friend class with example. [5]
A friend function is a function that is not a member of a class but has access to the private and protected members of that class. It is declared inside the class using the keyword friend. Key Points: - It is defined outside the class scope - It is not call...
Full solved answer →What is friend function? Write a program to add private member of two different classes using friend function. [5]
A friend function is a function that is not a member of a class but has access to the private and protected members of that class. It is declared inside the class using the keyword friend, but it is defined outside the class like a normal function. Key Poin...
Full solved answer →What is friend function? Write a program to add any two private numbers of two different classes using friend function. [1+4]
A friend function is a function that is not a member of a class but has access to the private and protected members of that class. It is declared inside the class using the keyword friend. A friend function can be a friend of more than one class at the same...
Full solved answer →Inline functions
Explain advantages and disadvantages of inline function. [5]
An inline function is a function declared with the inline keyword that requests the compiler to replace the function call with the actual function body code at the point of invocation, rather than performing a normal function call. --- - The function body i...
Full solved answer →Friend classes
Why do we need friend class? How can we define member function outside the class? [5]
In C++, data members declared as private or protected are not accessible from outside the class. This enforces data encapsulation. However, sometimes it is necessary for an external class or function to access the private and protected members of another cl...
Full solved answer →Function overloading
What is function overloading? Explain with an example. [5]
Function overloading is a feature in C++ (and other OOP languages) that allows multiple functions to have the same name but with different parameter lists (different number, type, or order of parameters). The compiler determines which function to call based...
Full solved answer →Make Unit 5 stick
Practice BIT153 with flashcards & quizzes