代码是否交换数组的两个数字
Does the code swap two numbers of the array?
实际
参数中应包含"&"以给出所需的结果,但以下代码也会正确交换数字。如何?
void swap(int *a, int *b){
int t=*a;
*a=*b;
*b=t;
}
//there is an array ar[]
swap(ar[0],ar[1]);
它应该给出一些垃圾值,但它给出了正确的答案。
函数调用实际上可能是在调用库定义的std::swap
函数,而不是自定义交换函数(因为类型不匹配(。
更改函数的名称,看看它是否可以编译。
相关文章:
- C++通过数字比较两个数字
- 将向量之间的数字放在另一个向量之间<vector>>如果两个数字的差值为 1
- 在 txt 文件中显示前两个数字的程序
- 形成一个斐波那契三角形,使得每个数字是上面左对角线或右对角线上两个数字的总和
- 两个数字的对称配对功能
- 查找中间两个数字的正则表达式的匹配项
- 使用C++具有两个数字的最短路径算法.(C++)
- 将两个数字添加为链表
- C++ 分段错误:11 错误,同时编码将两个数字相加的链接列表
- 我应该如何使用remove_if删除两个数字范围内的元素
- 是否有任何内置函数可以检查给定的两个数字在给定整数数组中的顺序是否相同?
- 子数组中两个数字的相同出现(连续)
- 如何使用位操作在单个整数中编码和解码两个数字
- 在 c++ 程序中调试链表以添加两个数字: 有人可以解释为什么 l3=l3->next;导致错误?
- 钻头以两个数字替换位
- C 如何在小数系统中添加两个数字
- 为什么我的代码不给最后两个数字
- 如何在给出前两个数字的级数中找到大于 x 的第 n 个最小子数组总和?
- 输入两个数字后程序关闭
- 代码是否交换数组的两个数字