当前位置:网站首页>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’.
边栏推荐
- JDBC calls the stored procedure with call and reports an error
- Demander le Code de texte standard correspondant à un centre de travail dans l'ordre de production
- Query the standard text code corresponding to a work center (s) in the production order
- Note the various data set acquisition methods of jvxetable
- Li Chuang EDA learning notes 12: common PCB board layout constraint principles
- 入侵检测领域数据集总结
- 【经验】UltralSO制作启动盘时报错:磁盘/映像容量太小
- Summary of data sets in intrusion detection field
- Redis消息队列
- Auto.js学习笔记17:基础监听事件和UI简单的点击事件操作
猜你喜欢

High quality coding tool clion

Construction of yolox based on paste framework

Station B Liu Erden softmx classifier and MNIST implementation -structure 9

P2802 回家

PDK process library installation -csmc

Application Security Series 37: log injection

Redis message queue

CoDeSys note 2: set coil and reset coil

A master in the field of software architecture -- Reading Notes of the beauty of Architecture
![[Jiudu OJ 07] folding basket](/img/a7/e394f32cf7f02468988addad67674b.jpg)
[Jiudu OJ 07] folding basket
随机推荐
实践分享:如何安全快速地从 Centos迁移到openEuler
Node 之 nvm 下载、安装、使用,以及node 、nrm 的相关使用
Sequoiadb Lake warehouse integrated distributed database, June 2022 issue
Auto.js学习笔记17:基础监听事件和UI简单的点击事件操作
B站刘二大人-多元逻辑回归 Lecture 7
H3C S5820V2_5830V2交换机IRF2堆叠后升级方法
Sword finger offer II 039 Maximum rectangular area of histogram
Classes and objects (I) detailed explanation of this pointer
[experience] when ultralso makes a startup disk, there is an error: the disk / image capacity is too small
High quality coding tool clion
Query the standard text code corresponding to a work center (s) in the production order
Anti shake and throttling are easy to understand
Processes and threads
移植InfoNES到STM32
My 2021
Codeless June event 2022 codeless Explorer conference will be held soon; AI enhanced codeless tool launched
Go language -- language constants
[experience] install Visio on win11
Detailed summary of SQL injection
[QNX Hypervisor 2.2用户手册]6.3.3 使用共享内存(shmem)虚拟设备