C 中的内存操作函数-memcpy 等(to be continued)
生活随笔
收集整理的這篇文章主要介紹了
C 中的内存操作函数-memcpy 等(to be continued)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- C中的內存操作函數
- 1.memcpy()
- 1.1 函數介紹
- 1.2 示例代碼
- 1.3 Reference
C中的內存操作函數
1.memcpy()
1.1 函數介紹
void *memcpy(void*dest, const void *src, size_t n);表示從 src 開始連續復制 n 個單位的數據到 dest 中,結果返回一個指向 dest 的指針。
需要注意的幾點:
1.2 示例代碼
將字符串復制到字符串數組中
//作用:將s中的字符串復制到字符數組d中。//memcpy.c#include<stdio.h>#include<string.h>int main(){char* s="Golden Global View";char d[20];clrscr();memcpy(d,s,strlen(s));d[strlen(s)]='\0';//因為從d[0]開始復制,總長度為strlen(s),d[strlen(s)]置為結束符printf("%s",d);getchar();return 0;}//輸出結果:GoldenGlobal View1.3 Reference
總結
以上是生活随笔為你收集整理的C 中的内存操作函数-memcpy 等(to be continued)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 手机端移动框架简介
- 下一篇: [Math][Algebra]--线性代