指点成金-最美分享吧

登录

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

佚名 举报

篇首语:本文由小编为大家整理,主要介绍了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

#includeint 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操作系统下运行结果如下:

以上是关于C语言中long类型指针类型长度到底是多少的主要内容,如果未能解决你的问题,请参考以下文章