当前位置:网站首页>【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 &
边栏推荐
- Hls4ml/vivado HLS error reporting solution
- js三元表达式复杂条件判断
- Technology T3 domestic platform! Successfully equipped with "Yihui domestic real-time system sylixos"
- Transaction isolation level gap lock deadlock
- Procédure de mesure du capteur d'accord vibrant par le module d'acquisition d'accord vibrant
- February 15, 2022: sweeping robot. There is a floor sweeping robot in the room (represented by a grid). Each grid in the grid has two possibilities: empty and obstacles. The sweeping robot provides fo
- SQL 入门计划-1-选择
- Bao, what if the O & M 100+ server is a headache? Use Xingyun housekeeper!
- Axure does not display catalogs
- Regular expression =regex=regular expression
猜你喜欢
Graduation season | Huawei experts teach the interview secret: how to get a high paying offer from a large factory?
The key to the success of digital transformation enterprises is to create value with data
JVM memory model
Procédure de mesure du capteur d'accord vibrant par le module d'acquisition d'accord vibrant
How to configure webrtc video streaming format for easygbs, a new version of national standard gb28181 video platform?
[research materials] iResearch tide Watching: seven major trends in the clothing industry - Download attached
Uni app product classification
Is Dao safe? Build finance encountered a malicious governance takeover and was looted!
实例讲解将Graph Explorer搬上JupyterLab
3D全景模型展示可视化技术演示
随机推荐
703. The k-th element in the data flow
【AI服务器搭建】CUDA环境
Cookie和Session的相关概念
Simplified pinduoduo product data
一个程序员如何快速成长
Hls4ml entry method
为定时器和延时器等其它情况的回调函数绑定当前作用域的this
科技T3国产平台!成功搭载“翼辉国产实时系统SylixOS”
Win11快捷键切换输入法无反应怎么办?快捷键切换输入法没有反应
使用Zadig从0到1搭建持续交付平台
Review the collection container again
Test self-study people must see: how to find test items in software testing?
mysql 报错 Can‘t create table ‘demo01.tb_Student‘ (errno: 150)*
使用 Kibana Timelion 进行时间序列分析
再回顾集合容器
qobject_cast用法
2022/6/8-2022/6/12
EasyCVR通过国标GB28181协议接入设备,出现设备自动拉流是什么原因?
[research data] observation on the differences of health preservation concepts among people in 2022 - Download attached
Anaconda安装虚拟环境到指定路径