C++ Programming
FUNCTION TEMPLATES MCQs
Total Questions : 5
Answer is Option C. -> a or b
None.
Answer is Option C. -> constant expression
Non-type template parameters provide the ability to pass a constant expression at compile time.
The constant expression may also be an address of a function, object or static class member.
Answer is Option C. -> constant expression
Answer:d
Explanation:In this program, We are using the for loop to increment the value by 1 in the function template.
Output:
$ g++ ftemp5.cpp
$ a.out
2.1
3.1
4.1
Question 4.
1.
#include
2.
using namespace std;
3.
template
4.
inline T square(T x)
5.
{
6.
T result;
7.
result = x * x;
8.
return result;
9.
};
10.
int main()
11.
{
12.
int i, ii;
13.
float x, xx;
14.
double y, yy;
15.
i = 2;
16.
x = 2.2;
17.
y = 2.2;
18.
ii = square(i);
19.
cout
What is the output of this program?
1.
#include
2.
using namespace std;
3.
template
4.
inline T square(T x)
5.
{
6.
T result;
7.
result = x * x;
8.
return result;
9.
};
10.
int main()
11.
{
12.
int i, ii;
13.
float x, xx;
14.
double y, yy;
15.
i = 2;
16.
x = 2.2;
17.
y = 2.2;
18.
ii = square(i);
19.
cout
Answer is Option C. -> constant expression
Answer:a
Explanation:In this program, We are passing the values and calculating the square of the value by using the function template.
Output:
$ g++ ftemp4.cpp
$ a.out
2 4
2.2 4.84
Answer is Option B. -> 200
In this program, We are using class to pass the value and then we are manipulating it.
Output:
$ g++ ftemp3.cpp
$ a.out
200
Recent Questions
Q. DIVA:OPERA
Q. All Computers Must Have __________
Q. Which Of The Following Statements Are Correct With Regard To....
Q. (solve As Per The Direction Given Above)
Q. Deficiency Of 'Thiamine' Causes
Q. In Each Question Below A Sentence Broken Into Four Or Five P....
Q. IRS 1A And 1B Satellites Can Carry Which Of The Following Se....
Q. ....
Q. For A Dc Machine Shunt Resistance And Armature Resistance Va....
Q. ....
Q. Who Among The Following Was The First English Man To Visit W....
Q. Find The Correctly Spelt Word
Q. The Color Of Fluorine Is
Q. Rashi Went toy Shopping With Her Mother And Saw A Toy ....
Q. The Process Partially Responsible For The Life On Earth Is
Q. What Is The Place Of The Indian Men's Cricket Team In The La....
Q. ....
Q. Match The Following: 1. Nishka (i) Later Vedic Coi....
Q. Which Fertiliser Is Made (using Coke Oven Gas) In By Product....
Q. ....