日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

【C语言】【笔试题】模拟实现memcmp

發(fā)布時(shí)間:2025/5/22 70 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【C语言】【笔试题】模拟实现memcmp 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
#include?<stdio.h> #include?<stdlib.h> #include?<assert.h> int?my_memcmp1(const?void?*p1,?const?void?*p2,?size_t?count)//方法1 {assert(p1);assert(p2);char?*dest?=?(char?*)p1;char?*src?=?(char*)p2;while?(count?&&?(*dest?==?*src)){count--;dest++;src++;}if?(count?==?0)return?0;return?*dest?-?*src; } int?my_memcmp2(const?void?*p1,?const?void?*p2,?size_t?count)//方法2 {assert(p1);assert(p2);int?ret?=?0;char?*dest?=?(char?*)p1;char?*src?=?(char*)p2;while?(count?&&?(!(ret?=?(*dest?-?*src)))){dest++;src++;count--;}if?(ret?>?0){return?1;}else?if?(ret?<?0){return?-1;}return?0;}int?main() {int?arr1[]?=?{1,2,3,4,5,6};int?arr2[]?=?{1,2,3,1000000,5,6};//清楚內(nèi)存是怎樣放置的int?ret?=?my_memcmp2(arr1,?arr2,?16);printf("%d",?ret);system("pause");return?0; }

轉(zhuǎn)載于:https://blog.51cto.com/10740329/1715699

總結(jié)

以上是生活随笔為你收集整理的【C语言】【笔试题】模拟实现memcmp的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。