有没有换用C两个变量内置方式 [英] Is there a built-in way to swap two variables in C
本文介绍了有没有换用C两个变量内置方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道如何在交换C ++ 2个变量,即您使用的std ::互换(A,B)
。
I know how to swap 2 variables in c++ , ie you use std::swap(a,b)
.
问题:
请问 C
标准库中也有类似的功能,以C ++ 的std ::互换()
还是我定义它自己。
Does the C
standard library have a similar function to C++ std::swap()
or do I have to define it myself.
推荐答案
有在C中没有等价物 - 事实上不可能有,因为C没有模板函数。你将不得不写你想要交换的各类独立的功能。
There is no equivalent in C - in fact there can't be, as C doesn't have template functions. You will have to write separate functions for all the types you want to swap.
这篇关于有没有换用C两个变量内置方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文