设为首页 加入收藏

TOP

C语言查看各种数据类型的size
2015-12-15 23:09:06 来源: 作者: 【 】 浏览:1
Tags:语言 查看 各种 数据 类型 size

C语言查看各种数据类型的size


intptr_t 定义在/usr/include/stdint.h,


#if __WORDSIZE == 64


# ifndef __intptr_t_defined
typedef long int intptr_t;
# define __intptr_t_defined
# endif
typedef unsigned long int uintptr_t;
#else
# ifndef __intptr_t_defined
typedef int intptr_t;
# define __intptr_t_defined
# endif
typedef unsigned int uintptr_t;
#endif


?


#include


#include


int main(void)
{
? ? int *ptr;
? ? printf("sizeof int is %d\n",sizeof(int));
? ? printf("sizeof char is %d\n",sizeof(char));
? ? printf("sizeof short is %d\n",sizeof(short));
? ? printf("sizeof long is %d\n",sizeof(long));
? ? printf("sizeof float is %d\n",sizeof(float));
? ? printf("sizeof double is %d\n",sizeof(double));
? ? printf("sizeof pointer is %d\n",sizeof(ptr));
? ? printf("sizeof unsiged int is %d\n",sizeof(unsigned int));
? ? //store pointers in integer type,use size_t,INT_PTR,intptr_t;
? ? printf("sizeof size_t is %d\n",sizeof(size_t));
? ? //intptr_t defines in stdint.h
? ? printf("sizeof intptr_t is %d\n",sizeof(intptr_t));
? ? //INT_PTR only exist in windows
? ? //printf("sizeof INT_PTR is %d\n",sizeof(INT_PTR));
? ?
}


查看各种数据类型的MAX 和MIN 值


#include


#include
#include
int main()
{
printf("The value of INT_MAX is %i\n", INT_MAX);
printf("The value of INT_MIN is %i\n", INT_MIN);
printf("An int takes %d bytes\n", sizeof(int));


printf("The value of FLT_MAX is %f\n", FLT_MAX);
printf("The value of FLT_MIN is %.50f\n", FLT_MIN);
printf("A float takes %d bytes\n", sizeof(float));


printf("The value of CHAR_MAX is %d\n", CHAR_MAX);
printf("The value of CHAR_MIN is %d\n", CHAR_MIN);
printf("A CHAR takes %d bytes\n", sizeof(char));


printf("The value of DBL_MAX is %f\n", DBL_MAX);
printf("The value of DBL_MIN is %.50f\n", DBL_MIN);
printf("A double takes %d bytes\n", sizeof(double));


printf("The value of SHRT_MAX is %d\n", SHRT_MAX);
printf("The value of SHRT_MIN is %d\n", SHRT_MIN);
printf("A short takes %d bytes\n", sizeof(short));


printf("The value of LONG_MAX is %Ld\n", LONG_MAX);
printf("The value of LONG_MIN is %Ld\n", LONG_MIN);
printf("A long takes %d bytes\n", sizeof(long));
return 0;
}


在stdint.h 里面定义了很多int*_t 和uint*_t 类型。


#include


#include
#include


int main(int argc, char *argv[])
{
? ? printf("CHAR_BIT is %d\n\n",CHAR_BIT);
? ? printf("sizeof(char) is %d\n",sizeof(char));
? ? printf("sizeof(short) is %d\n",sizeof(short));
? ? printf("sizeof(int) is %d\n",sizeof(int));
? ? printf("sizeof(long) is %d\n",sizeof(long));
? ? printf("sizeof(long long) is %d\n\n",sizeof(long long));
? ?
? ? printf("sizeof(int8_t) is %d\n",sizeof(int8_t));
? ? printf("sizeof(int16_t) is %d\n",sizeof(int16_t));
? ? printf("sizeof(int32_t) is %d\n",sizeof(int32_t));
? ? printf("sizeof(int64_t) is %d\n\n",sizeof(int64_t));


? ? printf("sizeof(uint8_t) is %d\n",sizeof(uint8_t));
? ? printf("sizeof(uint16_t) is %d\n",sizeof(uint16_t));
? ? printf("sizeof(uint32_t) is %d\n",sizeof(uint32_t));
? ? printf("sizeof(uint64_t) is %d\n",sizeof(uint64_t));
? ?
? ? char a,b;
? ? printf("sizeof(a+b) is %d\n",sizeof(a+b));
? ? }


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Java编码约定 下一篇Python3 多线程下载代码

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: