Chinaunix首页 | 论坛 | 博客
  • 博客访问: 61177
  • 博文数量: 96
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 852
  • 用 户 组: 普通用户
  • 注册时间: 2014-07-13 20:47
个人简介

扎斯特都恩特

文章分类

全部博文(96)

文章存档

2018年(1)

2017年(2)

2016年(82)

2015年(11)

我的朋友

分类: C/C++

2015-08-08 19:46:51

一、strlen
计算字符串的长度(不包括最后的'\0'),碰到第一个'\0'停止
eg:

点击(此处)折叠或打开

  1. #include <stdio.h>
  2. #include <string.h>

  3. int main()
  4. {
  5.     unsigned char *ucpStr = "ThisIsAStrlenTest";
  6.     printf("strlen :%d\n",strlen(ucpStr));
  7.     printf("Hello ,I'm LeTian!\n");
  8.     while(1);
  9. }

  10. 运行结果:
  11. strlen :17
  12. Hello ,I'm LeTian!
二、sizeof
返回变量或者类型在内存中占的字节数

点击(此处)折叠或打开

  1. #include <stdio.h>
  2. #include <string.h>

  3. typedef struct student
  4. {
  5.     unsigned char ucName;
  6.     unsigned int uiNum;
  7.     struct student *student1;
  8. }t_STUDENT;

  9. typedef unsigned int UINT32;

  10. int main()
  11. {
  12.     unsigned int i = 0;
  13.     unsigned char c = 0;
  14.     unsigned char *p =NULL;
  15.     
  16.     printf("sizeof i:%d\n",sizeof(i));
  17.     printf("sizeof c:%d\n",sizeof(c));
  18.     printf("sizeof p:%d\n",sizeof(p));
  19.     
  20.     printf("sizeof UINT32:%d\n",sizeof(UINT32));    
  21.     
  22.     printf("sizeof t_STUDENT:%d\n",sizeof(t_STUDENT));
  23.     
  24.     printf("Hello ,I'm LeTian!\n");
  25.     while(1);
  26. }

  27. 运行结果:
  28. sizeof i:4
  29. sizeof c:1
  30. sizeof p:4
  31. sizeof UINT32:4
  32. sizeof t_STUDENT:12
  33. Hello ,I'm LeTian!
由结果可以看出(32-bit的处理器)
1)指针占4 Bytes
2)char型在结构中时占4 Bytes,在函数体中时为1 Byte





阅读(560) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:C 语言常见编译错误

给主人留下些什么吧!~~