首頁  >  文章  >  後端開發  >  C語言中的記憶體操作是什麼?

C語言中的記憶體操作是什麼?

王林
王林轉載
2023-08-26 13:05:081074瀏覽

C語言中的記憶體操作是什麼?

庫 #include 包含了基本的記憶體運算。雖然不嚴格屬於字串函數,但這些函數的原型在 #include 中宣告。

這些記憶體運算如下:

void *memchr (void *s, int c, size_t n); 在緩衝區中搜尋字元。
int memcmp (void *s1, void *s2, size_t n); 比較兩個緩衝區。
void *memcpy (void *dest, void *src, size_t n); 將一個緩衝區複製到另一個緩衝區。
void *memmove (void *dest, void *src, size_t n); 將一定數量的位元組從一個緩衝區移到另一個緩衝區。
void *memset (void *s, int c, size_t n); 將緩衝區的所有位元組設定為給定字元。

請注意,在所有情況下,都是複製位元組的記憶體。 sizeof() 函數再次派上了用場。

memcpy(dest, src, SIZE); 複製字元(位元組)
memcpy( idest, isrc, SIZE*sizeof(int)); 複製整數陣列

##

memmove() behaves in exactly the same way as memcpy() except, that the source and destination locations may overlap.

memcmp() is similar to strcmp() except here, unsigned bytes are compared and returns less than zero if si is less than s2 etc.

例如,

char src[SIZE], dest[SIZE];
int isrc[SIZE], idest[SIZE];

以上是C語言中的記憶體操作是什麼?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除