填空题
有如下程序:
#include <iostream>
using namespace std;
template <typename T>
T total( T *data)
{
T s=0;
while (*data)
s+=*data++;
return s;
}
int main ()
{
int x[]={2,4,6, 8,0, 12, 14,16, 18 };
cout<<total (x);
return 0;
}
执行上面程序的输出结果是{{U}} 【13】 {{/U}}。
【正确答案】
1、20
【答案解析】[解析] 函数模板实现的功能是计算所传入数组data中元素值为0的元素前面所有元素值的和。