C++ Inline Function Aptitude Questions and Answers

C++ Inline Function Aptitude: This section contains C++ Inline Function Aptitude Questions and Answers with explanations.
Submitted by Nidhi, on February 19, 2021

1) There are the following statements that are given below, which of them are correct about inline function?

  1. Inline functions are a special type of function, which is used to reduce function call overhead.
  2. If we mark a function as an inline, then the definition of that function is substituted at the place of call.
  3. We cannot make every function as an inline function.
  4. Inline is the request to the compile.

Options:

  1. A and B
  2. A and C
  3. A, B, and D
  4. A, B, C, and D

2) Which of the following keyword is used to mark a function as an inline function?

Options:

  1. in
  2. iline
  3. inline
  4. Inline

3) Can we create only member functions as an inline function?

  1. Yes
  2. No

4) The functions defined in the class are by default mark as an inline function?

  1. Yes
  2. No

5) What is the correct output of given code snippets in C++?

#include <iostream>
using namespace std;

inline void myfun();

int main()
{
    myfun();
    return 0;
}

inline void myfun()
{
    cout << "Hello from inline function";
}

Options:

  1. Hello from inline function
  2. Syntax error
  3. Runtime error
  4. Linker error

6) What is the correct output of given code snippets in C++?

#include <iostream>
using namespace std;

inline void myfun();

int main()
{
    myfun();
    return 0;
}

void myfun()
{
    cout << "Hello from inline function";
}

Options:

  1. Hello from inline function
  2. Syntax error
  3. Runtime error
  4. Linker error

7) What is the correct output of given code snippets in C++?

#include <iostream>
using namespace std;

class Sample {
public:
    inline void myfun();
};

void Sample::myfun() inline
{
    cout << "Hello from inline function";
}

int main()
{
    Sample S;

    S.myfun();
    return 0;
}

Options:

  1. Hello from inline function
  2. Syntax error
  3. Runtime error
  4. Linker error

8) What is the correct output of given code snippets?

#include <iostream>
using namespace std;

class Sample {
public:
    inline void myfun();
};

void inline Sample::myfun()
{
    cout << "Hello from inline function";
}

int main()
{
    Sample S;

    S.myfun();
    return 0;
}

Options:

  1. Hello from inline function
  2. Syntax error
  3. Runtime error
  4. Linker error

9) Can we create a constructor as an inline function?

  1. Yes
  2. No

10) Which of the following statements are correct about inline functions?

  1. If a function contains a loop can never be inline.
  2. If a function contains static variables can never be inline.
  3. If a function contains switch and goto statements can never be inline.
  4. If a function contains a recursive call can never be inline.

Options:

  1. A and B
  2. C and D
  3. A, B, and C
  4. A, B, C, and D





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.