惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
爱范儿
爱范儿
T
The Exploit Database - CXSecurity.com
量子位
T
Tailwind CSS Blog
T
Threatpost
The GitHub Blog
The GitHub Blog
AWS News Blog
AWS News Blog
云风的 BLOG
云风的 BLOG
K
Kaspersky official blog
P
Proofpoint News Feed
博客园 - 司徒正美
L
LangChain Blog
T
Threat Research - Cisco Blogs
C
CERT Recently Published Vulnerability Notes
罗磊的独立博客
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 叶小钗
S
Secure Thoughts
The Last Watchdog
The Last Watchdog
Spread Privacy
Spread Privacy
H
Hacker News: Front Page
T
Troy Hunt's Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
W
WeLiveSecurity
A
Arctic Wolf
Apple Machine Learning Research
Apple Machine Learning Research
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
P
Proofpoint News Feed
T
Tor Project blog
T
The Blog of Author Tim Ferriss
I
Intezer
P
Privacy & Cybersecurity Law Blog
美团技术团队
N
Netflix TechBlog - Medium
博客园_首页
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Vulnerabilities – Threatpost
Application and Cybersecurity Blog
Application and Cybersecurity Blog
G
Google Developers Blog
Attack and Defense Labs
Attack and Defense Labs
T
Tenable Blog
月光博客
月光博客
Stack Overflow Blog
Stack Overflow Blog
J
Java Code Geeks
腾讯CDC
Microsoft Security Blog
Microsoft Security Blog
A
About on SuperTechFans
Last Week in AI
Last Week in AI

博客园 - Lunais

恢复 git stash drop 丢失的内容 Git技巧:彻底重置本地仓库与远程同步,同时保留Stash内容 信源编码和信道编码区别 Leetcode scanf 一组数据差值之和最大 5G 3gpp协议 eclipse调试配置 find查找 浮点类型(float、double)在内存中的存储 yield python2处理表格文件按照规则多行输出(中文路径,print) linux系统objdump输出动态库.so文件和静态库.a中符号表 python复制删除文件&修改目录&执行bat(wins) Linux C下的正则表达式 kill eclipse C语言之表达式运算整体提升 查找函数对比:findall,search,match Linux backtrace() git本地协同
[基础函数]memset用法
Lunais · 2021-06-23 · via 博客园 - Lunais

这个基础函数,主要见过两种用法:

1.内存初始化

2.考试!!!(鉴于经常考试翻车,立个flag,逢考必对~)

memset声明:

void * memset ( void * ptr, int value, size_t num );

memset入参:

ptr:
  Pointer to the block of memory to fill.
value:
  Value to be set. The value is passed as an int, but the function fills the block of memory using the unsigned char conversion of this value.
num:
  Number of bytes to be set to the value.  size_t is an unsigned integral type.
由于是按照字节赋值,来看一个经典考试题
 1 #include "stdio.h"
 2 #include "string.h"
 3 
 4 int main()
 5 {
 6     int i = 0;
 7     memset(&i, 256, sizeof(i));
 8 
 9     unsigned char* m = (unsigned char*)(&i);
10     for (int j = 0; j < sizeof(i); j++)
11     {
12         printf("%d\n", m[j]);
13     }
14     return 0;
15 }

output:0000
memset(&i, 128, sizeof(i));
output:
128
128
128
128
256是0x100,取一个无符号字节是0x00
128是0x80(0b1000 0000 或者 128),取一个无符号字节是0x80