当前位置:网站首页>【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通过国标GB28181协议接入设备,出现设备自动拉流是什么原因?
- Leetcode 1380 lucky numbers in matrix [array] the leetcode path of heroding
- Related concepts of cookies and sessions
- 毕业季 | 华为专家亲授面试秘诀:如何拿到大厂高薪offer?
- Analysis of GetMessage underlying mechanism
- Botu V16 obtains the system time and converts it into a string
- 2022/6/8-2022/6/12
- JVM memory model
- 利用win7漏洞进行系统登录密码破解
- Interview question 1
猜你喜欢

一个悄然崛起的国产软件,低调又强大!
![[research materials] iResearch tide Watching: seven major trends in the clothing industry - Download attached](/img/c8/a205ddc2835c87efa38808cf31f59e.jpg)
[research materials] iResearch tide Watching: seven major trends in the clothing industry - Download attached

servlet知识点

Technology T3 domestic platform! Successfully equipped with "Yihui domestic real-time system sylixos"

Interesting! Database is also serverless!

Test self-study people must see: how to find test items in software testing?

P2433 【深基1-2】小学数学 N 合一

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

MYSLQ十种锁,一篇文章带你全解析

Oracle physical architecture
随机推荐
Leetcode 1380 lucky numbers in matrix [array] the leetcode path of heroding
DDR4 test-2
Compile ffmpeg source code with msys+vs2019 under win10
IPv4 address, subnet mask, gateway
JVM memory model
PowerDesigner design name and comment replacement
墨天轮沙龙 | 清华乔嘉林:Apache IoTDB,源于清华,建设开源生态之路
Use of common built-in classes of JS
Battery simulation of gazebo robot
[SQL optimization] the difference between with as and temporary tables
JS ternary expression complex condition judgment
3D全景模型展示可视化技术演示
Wechat applet navigator has a shadow after clicking. Remove the shadow effect of navigator
DS transunet: Dual Swing transformer u-net for medical image segmentation
After studying 11 kinds of real-time chat software, I found that they all have these functions
Related concepts of cookies and sessions
Salesmartly has some tricks for Facebook chat!
MySQL reports an error can't create table 'demo01 tb_ Student‘ (errno: 150)*
Wireshark packet analysis TCP, FTP
HLS4ML报错The board_part definition was not found for tul.com.tw:pynq-z2:part0:1.0.