C之memset、memcpy、strcpy、strncpy区别
生活随笔
收集整理的這篇文章主要介紹了
C之memset、memcpy、strcpy、strncpy区别
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1 memset
memset 用來對一段內(nèi)存空間全部設(shè)置為某個字符,一般用在對定義的字符串進行初始化為‘ ’或‘\0’, memset可以方便的清空一個結(jié)構(gòu)類型的變量或數(shù)組。
char a[100]; memset(a, '\0', sizeof(a));struct student {char name[16];int age; };
struct student student1; 一般情況下,清空student1: student1.name[0]='\0'; student1.age=0;memset就非常方便 memset(&student1,0,sizeof(struct student));
如果是數(shù)組:
struct student students[5]; memset(students,0,sizeof(struct student)*5);
2 memcpy
頭文件:#include <string.h>
memcpy() 用來復(fù)制內(nèi)存?
總結(jié)
以上是生活随笔為你收集整理的C之memset、memcpy、strcpy、strncpy区别的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android之在后台不显示activi
- 下一篇: C语言之理解(*(void (*)())