当前位置:网站首页>【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 &边栏推荐
- Wechat applet navigator has a shadow after clicking. Remove the shadow effect of navigator
- Transaction isolation level gap lock deadlock
- 通过js实现金字塔(星号金字塔,回文对称数字金字塔)
- STC 32位8051单片机开发实例教程 三 程序编译设置与下载
- Difference between redo and undo
- Easycvr accesses the equipment through the national standard gb28181 protocol. What is the reason for the automatic streaming of the equipment?
- Compile ffmpeg source code with msys+vs2019 under win10
- Linux下安装Redis,并配置环境
- 全国职业院校技能大赛网络安全“splunk“详细配置
- Basic use of MySQL
猜你喜欢

What is the essential difference between Bi development and report development?

面试题篇一

对象的创建

类加载机制

Actual combat of flutter - fast implementation of audio and video call application

Process steps of vibrating wire acquisition module for measuring vibrating wire sensor

【多线程】锁策略

墨天轮沙龙 | 清华乔嘉林:Apache IoTDB,源于清华,建设开源生态之路

【AI服务器搭建】CUDA环境

Win11如何取消任务栏隐藏?Win11取消任务栏隐藏的方法
随机推荐
MySQL signale une erreur can 't create table' demo01. TB Étudiant '(errno: 150)
Basic use of MySQL
qobject_ Cast usage
Uni app wechat applet one click login to obtain permission function
AAAI2020: Real-time Scene Text Detection with Differentiable Binarization
list大集合等比分割成多个小list集合
Use of common built-in classes of JS
Anaconda安装虚拟环境到指定路径
mysql 報錯 Can‘t create table ‘demo01.tb_Student‘ (errno: 150)*
Remove line breaks from MySQL query results
ModSim基本使用(Modbus模拟器)
【AI服务器搭建】CUDA环境
Shell advanced
After studying 11 kinds of real-time chat software, I found that they all have these functions
Gaussdb (for MySQL):partial result cache, which accelerates the operator by caching intermediate results
Battery simulation of gazebo robot
Win11暂停更新点不了怎么办?Win11暂停更新是灰色的如何解决?
Axure does not display catalogs
How can a programmer grow rapidly
PowerDesigner设计Name和Comment 替换