Quick viewing(Text Mode)

C++ Inline Function Interview Questions and Answers Guide

C++ Inline Function Interview Questions and Answers Guide

++ Interview Questions And Answers Guide.

Global Guideline. https://www.globalguideline.com/ C++ Inline Function Interview Questions And Answers

Global Guideline . COM C++ Inline Function Job Interview Preparation Guide.

Question # 1 What is an inline function? Answer:- An inline function is a combination of & function. At the time of declaration or definition, function name is preceded by word inline. When inline functions are used, the overhead of function call is eliminated. Instead, the statements of the function are copied at the place of each function call. This is done by the . Consider following example: #include using namespace std; inline int sqr(int x) { int y; y = x * x; return y; } int main() { int a =3, b; b = sqr(a); cout <

Question # 2 Explain advantages and disadvantages of using macro and inline functions? Answer:- A textual substitution is provided by a macro as a constant, where as an inline function is procedure which is called at each time. Although the macros have few advantages over inline functions, the disadvantages are numerous. For example, a macro can not perform type checking and validation, as these operations are performed in a function at the most. Everyone should decide for themselves to use them, but the use of inline functions over macros is advocated by Bjarne Struoustrup, the creator of C++. The imperative features of inline functions are frequently used with classes in C++. There is similarity between invoking normal functions and inline functions, except that, inline functions are never actually called. The inline functions, as their name suggests, are expanded in line at every time of invocation. All that is needed to invoke an inline function is to prefix the key word ‘inline' to the function. Read More Answers.

Question # 3 Please explain, do inline functions improve performance? Answer:- A function when defined as INLINE, the code from the function definition is directly copied into the code of the calling function. It avoids the overhead of calling the actual function. This is because the complier performs and which eliminates the time overhead when a function is called. Reduces space as no separate set of instructions in memory is written. Read More Answers.

Question # 4

Copyright © https://www.GlobalGuideline.COM Page 2/8 C++ Inline Function Interview Questions And Answers

Tell me what happens when recursion functions are declared inline? Answer:- The call to the body of the function is replaced by an inline function. This reduces the saving context on stack overhead. This process is efficient when the size of the function is small and invoked occasionally. Deep nesting of a method is done when a function is invoked recursively. The inline function is invoked recursively, and every call to itself is replaced with the body of the function, thus consumes a lot of code space. Read More Answers. Global Guideline . COM Question # 5 Can you please explain the difference between inline functions and macros? Answer:- A macro is a fragment of code which has been given a name. Whenever the name is used, it is replaced by the contents of the macro. There are two kinds of macros: Object-like macros and function-like macros. Inline function is a function that is expanded in line when the function is called. That is the compiler replaces the function call with the function code (similar to macros). The disadvantage of using macros is that the usual error checking does not occur during compilation.. Read More Answers.

Question # 6 Explain what are static member functions? Answer:- Static member functions are used to maintain a single copy of a class member function across various objects of the class. Static member functions can be called either by itself, independent of any object, by using class name and :: (scope resolution operator) or in connection with an object. Restrictions on static member functions are: 1. They can directly refer to other static members of the class. 2. Static member functions do not have this pointer. 3. Static member function can not be virtual. Read More Answers.

Question # 7 Define Inline Function? Answer:- When the function is defined Inline, the C++ compiler puts the function body inside the calling function. You can define function as Inline when the function body is small and need to be called many times, thus reduces the overhead in calling a function like passing values, passing control, returning values, returning control. Read More Answers.

Question # 8 Explain inline function? Answer:- An inline function is a combination of macro & function. At the time of declaration or definition, function name is preceded by word inline. When inline functions are used, the overhead of function call is eliminated. Instead, the executable statements of the function are copied at the place of each function call. This is done by the compiler. Consider following example: #include using namespace std; inline int sqr(int x) { int y; y = x * x; return y; } int main() { int a =3, b; b = sqr(a); cout <

Question # 9 Explain static member functions? Answer:- A static function can have an access to only other static members (functions or variables) declared in the same class. A static member function can be called using the class name instead of its objects. E.g. classname :: functionname; Read More Answers.

Question # 10 Described the advantages of using macro and inline functions? Copyright © https://www.GlobalGuideline.COM Page 3/8 C++ Inline Function Interview Questions And Answers

Answer:- A textual substitution is provided by a macro as a constant, where as an inline function is procedure which is called at each time. Although the macros have few advantages over inline functions, the disadvantages are numerous. For example, a macro can not perform type checking and validation, as these operations are performed in a function at the most. Read More Answers.

Question # 11 Global Guideline . COM Explain the difference between inline functions and macros? Answer:- A macro is a fragment of code which has been given a name. Whenever the name is used, it is replaced by the contents of the macro. There are two kinds of macros: Object-like macros and function-like macros. Inline function is a function that is expanded in line when the function is called. That is the compiler replaces the function call with the function code (similar to macros). The disadvantage of using macros is that the usual error checking does not occur during compilation. Read More Answers.

Question # 12 Does the inline functions improve performance? Answer:- A function when defined as INLINE, the code from the function definition is directly copied into the code of the calling function. * It avoids the overhead of calling the actual function. This is because the complier performs and inline expansion which eliminates the time overhead when a function is called. * Reduces space as no separate set of instructions in memory is written. Read More Answers.

Question # 13 Described the disadvantages of using macro and inline functions? Answer:- Everyone should decide for themselves to use them, but the use of inline functions over macros is advocated by Bjarne Struoustrup, the creator of C++. The imperative features of inline functions are frequently used with classes in C++. There is similarity between invoking normal functions and inline functions, except that, inline functions are never actually called. The inline functions, as their name suggests, are expanded in line at every time of invocation. All that is needed to invoke an inline function is to prefix the key word 'inline' to the function. Read More Answers.

Question # 14 described when recursion functions are declared inline? Answer:- The call to the body of the function is replaced by an inline function. This reduces the saving context on stack overhead. This process is efficient when the size of the function is small and invoked occasionally. Deep nesting of a method is done when a function is invoked recursively. The inline function is invoked recursively, and every call to itself is replaced with the body of the function, thus consumes a lot of code space. Read More Answers.

Question # 15 By default, if function with minimum lines of code is declared and defined inside the class becomes Inline function. a. True b. False Answer:- a. True Read More Answers.

Question # 16 Default return the type of functions in CPP is: a. void b. long c. char d. int Answer:- d. int Read More Answers.

Question # 17 Default values for function are specified when____. a. function is defined b. function is declared c. Both a and b d. None of these

Copyright © https://www.GlobalGuideline.COM Page 4/8 C++ Inline Function Interview Questions And Answers

Answer:- b. function is declared Read More Answers.

Question # 18 The Inline functions may Globalnot work ______. Guideline . COM 1. If function contain static variables 2. If function contain global and register variables 3. If function returning value consists looping construct(i.e. for, while) 4. If inline functions are recursive 5. If function contains const value a. Only 1,4,5 b. Only 2,3,5 c. Only 1,3,4 d. All of these Answer:- c. Only 1,3,4 Read More Answers.

Question # 19 If program uses Inline Function, then the function is expanded inline at ______. a. Compile time b. Run time c. Both a and b d. None of these Answer:- b. Run time Read More Answers.

Question # 20 Default values for function are need to be specified from left to right only. a. True b. False Answer:- b. False Explanation: Default values need to be specified from Right to Left order. Example: void calculate(int amt, int years, float rate=7.8); //valid void calculate(int amt, int years=5, float rate=7.8); //valid void calculate(int amt=21000, int years, float rate=7.8); //Invalid Third statement is invalid as we skipped second parameter of the function. Rule says that default values should be set from Right to Left order only. We cannot provide a default value to specific parameter in the middle of an parameter list. Read More Answers.

Question # 21 The Function overloading can also be achieved if two or more functions differ only in their return types. a. True b. False Answer:- b. False Read More Answers.

Question # 22 If an argument to function is declared as const, then: a. function can modify the argument b. Function can't modify the argument c. const argment to a function is not possible d. None of these Answer:- b. Function can't modify the argument Read More Answers.

Question # 23 In any ways, Non-member function cannot have access to private data of the class. a. True b. False Answer:-

Copyright © https://www.GlobalGuideline.COM Page 5/8 C++ Inline Function Interview Questions And Answers

b. False Read More Answers.

Question # 24 Function can be declared as friend maximum only in two classes. a. True b. False Global Guideline . COM Answer:- b. False Read More Answers.

Question # 25 Friend function does not have this pointer associated with it. a. True b. False Answer:- a. True Read More Answers.

Question # 26 Which of followings is/are not false about friend function? 1. It can be called / invoked with class object 2. It has objects as arguments 3. It can have built-in types as arguments 4. It must declared only in public part of a class 5. It does not have this pointer as an argument a. Only 2,4 b. Only 1,2,5 c. Only 2,3,5 d. All of these Answer:- c. Only 2,3,5 Read More Answers.

Question # 27 Assigning one or more function body to same name is called______. a. Function Overriding b. Function Overloading c. Both a and b d. None Answer:- b. Function Overloading Read More Answers.

Copyright © https://www.GlobalGuideline.COM Page 6/8 C++ Programming Most Popular Interview Topics.

1 : C++ Virtual Functions Frequently Asked Interview Questions and Answers Guide.

2 : C++ Operator Overloading Frequently Asked Interview Questions and Answers Guide.

3 : C++ Constructors Frequently Asked Interview Questions and Answers Guide.

4 : Basic C++ Syntax Frequently Asked Interview Questions and Answers Guide.

5 : C++ Exception Handling Frequently Asked Interview Questions and Answers Guide.

6 : C++ Inheritance Frequently Asked Interview Questions and Answers Guide.

7 : C++ Template Frequently Asked Interview Questions and Answers Guide.

8 : C++ Friend Frequently Asked Interview Questions and Answers Guide.

9 : C++ Access Control Frequently Asked Interview Questions and Answers Guide.

10 : C++ COM ActiveX Frequently Asked Interview Questions and Answers Guide. About Global Guideline.

Global Guideline is a platform to develop your own skills with thousands of job interview questions and web tutorials for fresher's and experienced candidates. These interview questions and web tutorials will help you strengthen your technical skills, prepare for the interviews and quickly revise the concepts. Global Guideline invite you to unlock your potentials with thousands of Interview Questions with Answers or begin a tutorial right away, such as HTML, XML, XSLT, Cascading Style Sheet (CSS), Search Engine Optimization (SEO), JavaScript, Structure Query Language (SQL), Database Articles, Web Hosting Guide and much more. Learn the most common technologies Interview Questions and Answers. We will help you to explore the resources of the World Wide Web and develop your own skills from the basics to the advanced. Here you will learn anything quite easily and you will really enjoy while learning. Global Guideline will help you to become a professional and Expert, well prepared for the future.

* This PDF was generated from https://www.GlobalGuideline.com at April 4th, 2021

* If any answer or question is incorrect or inappropriate or you have correct answer or you found any problem in this document then don't hesitate feel free and e-mail us we will fix it.

You can follow us on FaceBook for latest Jobs, Updates and other interviews material. www.facebook.com/InterviewQuestionsAnswers

Follow us on Twitter for latest Jobs and interview preparation guides https://twitter.com/InterviewGuide

Best Of Luck.

Global Guideline Team https://www.globalguideline.com [email protected]