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

C语言查看各种数据类型的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));

}

本文永久更新链接地址:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值