sizeof(p1) strlen(p1)
时间: 2023-09-27 18:07:34 浏览: 104
sizeof(p1)返回的是指针p1的大小,而不是字符串的长度。在引用\[2\]中,sizeof(p)返回的是指针p的大小,相当于sizeof(char *),所以结果是4。而strlen(p1)返回的是字符串p1的长度,即字符的个数,不包括字符串结束符'\0'。在引用\[3\]中,strlen(p)返回的是字符串p的长度,即5。
#### 引用[.reference_title]
- *1* *3* [C语言sizeof与strlen详解(附大量笔试题题解过程)](https://blog.csdn.net/chuxinchangcun/article/details/120219122)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [sizeof与strlen对比总结](https://blog.csdn.net/XD_hebuters/article/details/78477173)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文