函数strlen()和sizeof的区别

2023-02-17,,,

函数strlen()sizeof区别

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

#define SENTENCE "It is a cat"

int main()

{

char name[40];

gets(name);

printf("%s\n", name);

printf("The size of name is %zd %d\nThe size of  SENTENCE is %zd %d",strlen(name), sizeof(name), strlen(SENTENCE), sizeof(SENTENCE));//请注意strlen()和sizeof的区别!

return 0;

}

strlen()函数是计算实际字符串的长度,而sizeof不但计算了字符串的大小,还记算了字符串末尾不可见的空字符!

函数strlen()和sizeof的区别的相关教程结束。

《函数strlen()和sizeof的区别.doc》

下载本文的Word格式文档,以方便收藏与打印。