当前位置:网站首页>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’.
边栏推荐
- Vulhub vulnerability recurrence 73_ Webmin
- Station B, Master Liu Er - back propagation
- B站刘二大人-线性回归及梯度下降
- 局域网同一个网段通信过程
- 嵌入式面试题(四、常见算法)
- Pytorch代码注意的细节,容易敲错的地方
- [detailed explanation of Huawei machine test] statistics of shooting competition results
- Luogu [Beginner Level 4] array p1427 number game of small fish
- 类和对象(一)this指针详解
- Auto.js学习笔记17:基础监听事件和UI简单的点击事件操作
猜你喜欢

What is independent IP and how about independent IP host?

Application Security Series 37: log injection

Station B Liu Erden linear regression pytoch

B站刘二大人-反向传播

自建DNS服务器,客户端打开网页慢,解决办法
[email protected]树莓派"/>[email protected]树莓派

YYGH-11-定时统计

05. 博客项目之安全

Station B, Master Liu Er - dataset and data loading
[SQL Server Express Way] - authentification et création et gestion de comptes utilisateurs
随机推荐
[cloud native] 3.1 kubernetes platform installation kubespher
Some easy-to-use tools make your essay style more elegant
Yunxiaoduo software internal test distribution test platform description document
实践分享:如何安全快速地从 Centos迁移到openEuler
29io stream, byte output stream continue write line feed
01. Project introduction of blog development project
进程和线程
After the project is released, index Html is cached
B站刘二大人-多元逻辑回归 Lecture 7
嵌入式面试题(四、常见算法)
Self built DNS server, the client opens the web page slowly, the solution
05. Security of blog project
Yygh-11-timing statistics
Embedded interview questions (I: process and thread)
华为路由器如何配置静态路由
Download, install and use NVM of node, and related use of node and NRM
Application Security Series 37: log injection
What is independent IP and how about independent IP host?
PDK工艺库安装-CSMC
B站刘二大人-数据集及数据加载 Lecture 8