一、strlen
计算字符串的长度(不包括最后的'\0'),碰到第一个'\0'停止
eg:
-
#include <stdio.h>
-
#include <string.h>
-
-
int main()
-
{
-
unsigned char *ucpStr = "ThisIsAStrlenTest";
-
printf("strlen :%d\n",strlen(ucpStr));
-
printf("Hello ,I'm LeTian!\n");
-
while(1);
-
}
-
-
运行结果:
-
strlen :17
-
Hello ,I'm LeTian!
二、sizeof
返回变量或者类型在内存中占的字节数
-
#include <stdio.h>
-
#include <string.h>
-
-
typedef struct student
-
{
-
unsigned char ucName;
-
unsigned int uiNum;
-
struct student *student1;
-
}t_STUDENT;
-
-
typedef unsigned int UINT32;
-
-
int main()
-
{
-
unsigned int i = 0;
-
unsigned char c = 0;
-
unsigned char *p =NULL;
-
-
printf("sizeof i:%d\n",sizeof(i));
-
printf("sizeof c:%d\n",sizeof(c));
-
printf("sizeof p:%d\n",sizeof(p));
-
-
printf("sizeof UINT32:%d\n",sizeof(UINT32));
-
-
printf("sizeof t_STUDENT:%d\n",sizeof(t_STUDENT));
-
-
printf("Hello ,I'm LeTian!\n");
-
while(1);
-
}
-
-
运行结果:
-
sizeof i:4
-
sizeof c:1
-
sizeof p:4
-
sizeof UINT32:4
-
sizeof t_STUDENT:12
-
Hello ,I'm LeTian!
由结果可以看出(32-bit的处理器)
1)指针占4 Bytes
2)char型在结构中时占4 Bytes,在函数体中时为1 Byte
阅读(591) | 评论(0) | 转发(0) |