Chinaunix首页 | 论坛 | 博客
  • 博客访问: 47749
  • 博文数量: 15
  • 博客积分: 45
  • 博客等级: 民兵
  • 技术积分: 85
  • 用 户 组: 普通用户
  • 注册时间: 2012-03-14 16:12
个人简介

Nothing to tell

文章分类

全部博文(15)

文章存档

2015年(1)

2012年(14)

我的朋友
最近访客

分类:

2012-07-17 18:48:36

原文地址:关于sizeof和strlen 作者:FreedomXura

sizeof:计算某类数据在内存中所占的字节数
strlen:是一个函数,计算字符串的实际长度
如在32位系统中:
sizeof(int) = 4
sizeof(char)=1
sizeof(short)=2
sizeof计算所有指针变量,返回值都是4。
sizeof(数组)=这个数组所分配的内存的字节大小。

  1 #include <stdio.h>
  2
  3 int main()
  4 {
  5 printf("**************************************************\n");
  6 printf("sizeof(int) is %d\n",sizeof(int));
  7 printf("sizeof(char) is %d\n",sizeof(char));
  8 printf("sizeof(short) is %d\n",sizeof(short));
  9 printf("**************************************************\n");
 10 char str[]="Hello,world";
 11 printf("char str[]='Hello,world'\n");
 12 printf("sizeof(str) is %d\n",sizeof(str));
 13 printf("sizeof(*str) is %d\n",sizeof(*str));
 14 printf("**************************************************\n");
 15 char str1[100]="Hello,world";
 16 printf("char str1[100]='Hello,world'\n");
 17 printf("sizeof(str1) is %d\n",sizeof(str1));
 18 printf("**************************************************\n");
 19 char *p=NULL;
 20 printf("char *p=NULL\n");
 21 printf("sizeof(p) is %d\n",sizeof(p));
 22 printf("sizeof(*p) is %d\n",sizeof(*p));
 23 return 0;
 24 }


阅读(689) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~