嵌入式初学者一枚,在系统学习过C语言之后发现自己在程序中使用C库中的关键字以及库函数时,细节问题记忆混乱。导致一些程序出现一些不符合逻辑实现的code。提醒初学者一定要细学、慢学、沉下心认真学,灵活运用!
1:sizeof 关键字
功能:对象占用内存空间字节数
参数:数据类型或变量或数组名……
' 返回值 ':字节数
注:sizeof关键字只针对数据类型!!!
2:strlen 字符串处理函数
功能:测字符串长度的函数
参数:数组首地址
返回值:数组字符串的实际大小
注:1、使用时包含#include <string.h>
2、strlen不包含' \0 ',并且' \0 '是其结束的标志。
STRLEN(3) Linux Programmer's Manual STRLEN(3)
NAME
strlen - calculate the length of a string
SYNOPSIS
#include <string.h>
size_t strlen(const char *s);
DESCRIPTION
The strlen() function calculates the length of the string s, excluding
the terminating null byte ('\0').
RETURN VALUE
The strlen() function returns the number of characters in s.
参考书籍:运行环境参考linux-ubuntu
C程序设计(第四版)
嵌入式 linuxC语言程序设计