【发布时间】:2021-10-24 15:22:51
【问题描述】:
将两个数字作为输入并交换它们并打印交换后的值。你不需要打印任何东西,它已经被处理好了。只需实现给定的函数。函数看起来像这样。
pair < int, int > swap(pair < int, int > swapValues) {
int c;
c=swapValues.first;
swapValues.first=swapValues.second;
swapValues.second=c;
cout<<swapValues.first<<" "<<swapValues.second<<"\n";
}
【问题讨论】:
-
这段代码表现出未定义的行为,通过到达非
void函数的右大括号而不遇到return语句。换句话说:该函数承诺返回一个pair<int, int>,但实际上并没有返回任何东西。
标签: c++ stl std-pair garbage utility-method