当前位置:网站首页>The usage and difference between strlen and sizeof
The usage and difference between strlen and sizeof
2022-07-06 05:47:00 【Python's path to immortality】
strlen And sizeof Usage is easy to be confused Next, summarize the similarities and differences between the two I hope I can help you .
function strlen And operators sizeof Usage of :
strlen The code prototype is :size_t strlen(char const* str), It's a function the Pass in The parameter must be a character pointer char* type , And it has to be ‘\0’ ending ,strlen stay function Calculate all the time Used to calculate the specified string str The length of Not the memory size Encountered string str End identifier of ‘\0’ end barring ‘\0’.

![]()
sizeof yes C/C++ One of the operators in , Simply put, its function is to return the number of memory bytes occupied by an object or type , The parameter passed in can be Array 、 The pointer 、 type 、 object 、 Functions, etc Calculate at compile time , use sizeof To return the type and the statically allocated object 、 Space occupied by a structure or array , It has nothing to do with what it stores .
sizeof The meaning of the returned value is as follows :
Array —— The amount of array space allocated at compile time ( Include '\0');
The pointer —— The amount of space used to store the pointer (32 Bit system by 4,64 Bit system by 8);
type —— The amount of space occupied by this type ;
object —— The actual space occupied by the object ;
function —— The amount of space occupied by the return type of the function ( The return type of a function cannot be void).

function strlen And operators sizeof The difference between :
1.strlen Is the function Calculate... At run time ,sizeof It's the operator Calculate at compile time .
2.strlen Parameter type can only be character pointer And take ‘\0’ ending ,sizeof The parameter type can be function 、 The pointer 、 Array 、 type 、 Object etc. , Depending on the type of parameter sizeof The meaning of the returned value is also different .
3.strlen Calculate string length , Independent of memory occupied encounter ‘\0’ end , It doesn't contain '\0',sizeof Returns the number of memory bytes occupied by an object or type It has nothing to do with length contain ‘\0’.
边栏推荐
- Yunxiaoduo software internal test distribution test platform description document
- P2802 go home
- Web Security (V) what is a session? Why do I need a session?
- Deep learning -yolov5 introduction to actual combat click data set training
- 什么是独立IP,独立IP主机怎么样?
- [detailed explanation of Huawei machine test] check whether there is a digital combination that meets the conditions
- 05. Security of blog project
- LeetCode_ String inversion_ Simple_ 557. Reverse word III in string
- Station B, Master Liu Er - dataset and data loading
- How can large websites choose better virtual machine service providers?
猜你喜欢

Easy to understand IIC protocol explanation

27io stream, byte output stream, OutputStream writes data to file

What impact will frequent job hopping have on your career?

B站刘二大人-反向传播

Yygh-11-timing statistics

Sword finger offer II 039 Maximum rectangular area of histogram

Promise summary

First knowledge database

类和对象(一)this指针详解

The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
随机推荐
局域网同一个网段通信过程
H3C V7版本交换机配置IRF
H3C防火墙RBM+VRRP 组网配置
c语言——冒泡排序
无代码六月大事件|2022无代码探索者大会即将召开;AI增强型无代码工具推出...
Promise summary
After the project is released, index Html is cached
数字经济破浪而来 ,LTD是权益独立的Web3.0网站?
Processes and threads
Yunxiaoduo software internal test distribution test platform description document
Jushan database appears again in the gold fair to jointly build a new era of digital economy
Auto.js学习笔记17:基础监听事件和UI简单的点击事件操作
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Garbage collector with serial, throughput priority and response time priority
进程和线程
华为路由器忘记密码怎么恢复
Station B Liu Erden softmx classifier and MNIST implementation -structure 9
[experience] install Visio on win11
【华为机试真题详解】检查是否存在满足条件的数字组合
RustDesk 搭建一个自己的远程桌面中继服务器