只是自己做个笔记,防止以后忘记了
欢迎各位大佬补充。
数组个数计算:
strlen只适合计算字符串长度,计算其它类型,结果并不准确,
sizeof根据大小来进行计算,计算int类型时,准确无误,在计算字符类型时会将“\0”也计算进去,导致实际会多一个数。
int strlen(const char *str)
{
int cnt=0;
whilr((*str++)!=“\0”)
{
cnt++;
}
return cnt;
}
只是自己做个笔记,防止以后忘记了
欢迎各位大佬补充。
数组个数计算:
strlen只适合计算字符串长度,计算其它类型,结果并不准确,
sizeof根据大小来进行计算,计算int类型时,准确无误,在计算字符类型时会将“\0”也计算进去,导致实际会多一个数。
int strlen(const char *str)
{
int cnt=0;
whilr((*str++)!=“\0”)
{
cnt++;
}
return cnt;
}