Cpp: Inline Functions 7

MCQ’s Inline Functions

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Inline”.

1.
Name the function whose definition can be substituted at a place where its function call is made _________

a) friends function
b) inline function
c) volatile function
d) external function

2.
What will be the output of the following C++ code?

#include <iostream>
using namespace std;

inline void func1(int a, int b)
{
cout<<“a=”<<a<<” and b= “<<b<<endl;
}
inline int func2(int x)
{
return x*x;
}
int main()
{
int tmp;
func1(1,4);
tmp = func2(6);
cout<<“square val = “<<tmp<<endl;
return 0;
}

a)
a=1 and b=4
square val = 36
b) a=4 and b=1
c) error
d) square val = 36

3.
What will be the error (if any) in the following C++ code?

#include <iostream>
using namespace std;

inline void func1(float b)
{
cout<<b*2<<endl;
}
int main()
{
inline func1(2.2);
return 0;
}

a) No error
b) Error in statement: inline void func1(float b)
c) Error in statement: cout<<b*2<<endl;
d) Error in statement: inline func1(2.2);


4.
What will be the output of the following C++ code?

#include <iostream>
using namespace std;

inline void f1(char b)
{
cout<<int(b)<<endl;
}
int main()
{
f1(‘a’);
return 0;
}
a) a
b) 65
c) error
d) 97

5.
What will be the output of the following C++ code?

#include <iostream>
using namespace std;

void inline func1(char b[10])
{
cout<<b[2]<<endl;
}
int main()
{
func1(“catalyst”);
return 0;
}
a) s
b) t
c) a
d) error