关于function中含有funcion的输出问题

来源:百度知道 编辑:UC知道 时间:2024/06/05 00:12:44
#include<iostream.h>
f(int c)
{
c++;
cout<<c<<endl;
return c;
}
main()
{
int a=1;
cout<<a<<" "<<f(a)<<endl;
return 0;
}
//结果是
2(function预先读取)
1 2

#include<iostream>
using namespace std;
template<class elemType>
int print(elemType list[],int length);
template<class apvector>
int mergesort(apvector arrayA[],apvector arrayB[],apvector arrayAlength,apvector arrayBlength);
int main()
{
int arrayA[]={1,3,5,7,9};
cout<<"The array of A is ";
print(arrayA,5);
cout<<endl;
int arrayB[]={2,4,6,8};
cout<<"The array of B is ";
print(arrayB,4);
cout<<endl;
cout<<"After merge arrayA and arrayB then getting the array of C is ";
mergesort(arrayA,arrayB,5,4);

我没看明白你的意思,你的优先读取是什么意思?
是不是指在输出函数的输出内容没有全部计算出来前是不会输出?
按照这个意思,第一个程序可以理解,先用f的cout输出2在用main里面的cout输出1 2;
第二个程序为什么要输出个asdf在那里?你的mergesort里面只有一个
print(arrayC,9);调用了个print函数,而print里面都是最终结果,不需要调用其他的了.