当前位置:网站首页>【C语言】详解 memset() 函数用法
【C语言】详解 memset() 函数用法
2022-07-01 18:47:00 【嵌入式职场】
1、memset 函数介绍
void * __cdecl memset(void *_Dst,int _Val,size_t _Size);
解释:复制字符 _Val(一个无符号字符)到参数 _Dst 所指向的字符串的前 _Size 个字符。memset 函数为初始化函数,可以把一段连续的内存初始化某个值。
作用:是在一段内存块中填充某个给定的值,它是对较大的结构体或数组进行清零操作的一种最快方法。
头文件:#include <string.h>
注意:memset 函数是按字节进行赋值的。
2、程序实例
对较大的结构体或数组进行清零操作
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// 结构体 People
typedef struct {
int m;
int n;
int z;
}People;
int main(){
// 分配内存空间
People *peo = (People*)malloc(sizeof(People));
// 使一段连续的内存初始化某一特定值
memset(peo,0, sizeof(People));
printf("m = %d\n",peo->m);
printf("n = %d\n",peo->n);
printf("z &
边栏推荐
- 开发那些事儿:EasyCVR集群设备管理页面功能展示优化
- After studying 11 kinds of real-time chat software, I found that they all have these functions
- How to use console Log print text?
- 1592 例题1 国王(Sgu223 LOJ10170 LUOGU1896 提高+/省选-) 暴力思考 状压DP 01背包
- JS 之 常用内置类的使用
- 利用win7漏洞进行系统登录密码破解
- Procédure de mesure du capteur d'accord vibrant par le module d'acquisition d'accord vibrant
- Uni app wechat applet one click login to obtain permission function
- EasyCVR集群视频广场页面切换时,请求流未能终止的问题优化
- Why has instagram changed from a content sharing platform to a marketing tool? How do independent sellers use this tool?
猜你喜欢
How to configure webrtc video streaming format for easygbs, a new version of national standard gb28181 video platform?
实例讲解将Graph Explorer搬上JupyterLab
HLS4ML报错The board_part definition was not found for tul.com.tw:pynq-z2:part0:1.0.
Oracle物理体系结构
GC垃圾回收
Regular expression =regex=regular expression
Use of common built-in classes of JS
Cookie和Session的相关概念
Wireshark packet analysis TCP, FTP
Interesting! Database is also serverless!
随机推荐
[untitled]
Servlet knowledge points
DDR4 test-2
GC garbage collection
Interesting! Database is also serverless!
Axure does not display catalogs
今日群里分享的面试题
703. The k-th element in the data flow
2022/5/23-2022/5/30
Interview question 1
P2433 [deep foundation 1-2] primary school mathematics n in one
Test self-study people must see: how to find test items in software testing?
类加载机制
振弦采集模塊測量振弦傳感器的流程步驟
Actual combat of flutter - fast implementation of audio and video call application
毕业季 | 华为专家亲授面试秘诀:如何拿到大厂高薪offer?
全国职业院校技能大赛网络安全“splunk“详细配置
Stack Overflow 2022 开发者调查:行业走向何方?
qobject_cast用法
Salesmartly has some tricks for Facebook chat!