C语言中long类型、指针类型长度到底是多少

决于操作系统采用的是哪个C Language Data Model

在32位的操作系统下,大部分的操作系统都是采用的ILP32,因此,long是4个字节

在64位的操作系统下,Windows采用的是LLP64,long是4个字节,指针是8个字节,类Unix操作基本都是采用的LP64,因此,long是8个字节。

参考文章:64位编程模型:为什么要使用LP64

                  Data Size Neutrality and 64-bit Support

#include<stdio.h>

int main(){
	char c;
	int i, *j;
	short si;
	long li;
	float f;
	double d;
	
	printf("Please input char:");//字符型 
	scanf("%c", &c);
	printf("Please input int:");//整形 
	scanf("%d", &i);
	printf("Please input short:");//短整形 
	scanf("%hd", &si);
	printf("Please input long:");//长整形 
	scanf("%ld", &li);
	printf("Please input float:");//单精度浮点型 
	scanf("%f", &f);	
	printf("Please input double:");//双精度浮点型 
	scanf("%lf", &d);	
	j = &i;
	
	printf("The char value is: %c, the size is %d:\n", c, sizeof(c));
	printf("The int value is: %d, the size is %d:\n", i, sizeof(i));
	printf("The short value is: %hd, the size is %d:\n", si, sizeof(si));
	printf("The long value is: %ld, the size is %d:\n", li, sizeof(li));
	printf("The float value is: %f, the size is %d:\n", f, sizeof(f));
	printf("The double value is: %lf, the size is %d:\n", d, sizeof(d));
	printf("The pointer value is: %d, the size is %d:\n", j, sizeof(j));	
}

64位Windows操作系统下运行结果如下:

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值