Home »
Aptitude Questions and Answers »
C++ Aptitude Questions and Answers
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?
- Inline functions are a special type of function, which is used to reduce function call overhead.
- If we mark a function as an inline, then the definition of that function is substituted at the place of call.
- We cannot make every function as an inline function.
- Inline is the request to the compile.
Options:
- A and B
- A and C
- A, B, and D
- A, B, C, and D
Correct Answer - 4
A, B, C, and D
Explanation:
All given statements are correct about inline functions.
2) Which of the following keyword is used to mark a function as an inline function?
Options:
- in
- iline
- inline
- Inline
Correct Answer - 3
inline
Explanation:
The inline keyword is used to mark a function as an inline function.
3) Can we create only member functions as an inline function?
- Yes
- No
Correct Answer - 2
No
Explanation:
No, we can create both member and non-member functions as an inline function.
4) The functions defined in the class are by default mark as an inline function?
- Yes
- No
Correct Answer - 1
Yes
Explanation:
Yes, the functions defined in the class are by default mark as an inline function.
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:
- Hello from inline function
- Syntax error
- Runtime error
- Linker error
Correct Answer - 1
Hello from inline function
Explanation:
The above code will print "Hello from inline function" on the console screen.
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:
- Hello from inline function
- Syntax error
- Runtime error
- Linker error
Correct Answer - 1
Hello from inline function
Explanation:
The above code will print "Hello from inline function" on the console screen.
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:
- Hello from inline function
- Syntax error
- Runtime error
- Linker error
Correct Answer - 2
Syntax error
Explanation:
The above code will generate syntax 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:
- Hello from inline function
- Syntax error
- Runtime error
- Linker error
Correct Answer - 1
Hello from inline function
Explanation:
The above code will print "Hello from inline function" on the console screen.
9) Can we create a constructor as an inline function?
- Yes
- No
Correct Answer - 1
Yes
Explanation:
Yes, we can create a constructor as an inline function.
10) Which of the following statements are correct about inline functions?
- If a function contains a loop can never be inline.
- If a function contains static variables can never be inline.
- If a function contains switch and goto statements can never be inline.
- If a function contains a recursive call can never be inline.
Options:
- A and B
- C and D
- A, B, and C
- A, B, C, and D
Correct Answer - 4
A, B, C, and D
Explanation:
All given statements are correct about inline functions.