比较两个相同长度的 int 数组的最佳方法? [英] Best way to compare two int arrays of the same length?
本文介绍了比较两个相同长度的 int 数组的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
比较 int 数组 b 和 c 与 a 的最佳方法是什么:
what is the best way to compare int arrays b and c with a:
int a[] = {0,1,0,0,1};
int b[] = {0,1,0,0,1};
int c[] = {1,1,0,0,1};
b 和 c 只是示例,假设它们可以是 0 和 1 的任意组合.
b and c are just examples, assume they can be any combination of 0s and 1s.
我正在尝试检测与 a 相同的数组.我用谷歌搜索了一段时间,没有找到满意的答案.
I am trying to detect arrays identical to a. I have googled this for a while and have not found a satisfactory answer.
我意识到这是一个初学者的问题,感谢您的耐心等待.
This is a beginners question I realise, thank you for your patience.
推荐答案
使用
中的标准 memcmp
函数.
Use the standard memcmp
function from <string.h>
.
memcmp(a, b, sizeof(a)) == 0
只要 a
和 b
相等.
这篇关于比较两个相同长度的 int 数组的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文