看你的linux编译系统是32位还是64位最简单的方法以及不同数据类型占用字节个数

本文介绍了一种简单的方法来确定Linux系统是32位还是64位,并通过示例展示了不同位数系统中C语言基本数据类型的字节大小。此外,还提供了检查Linux版本信息的命令。
看linux是32位还是64位最简单的方法:
getconf LONG_BIT
在32位和64位机器上运行如下命令,结果如下:
[b@002 ~]$ getconf LONG_BIT64[root@pmx4 /]# getconf LONG_BIT32
 
 

分类: C/C++

可用如sizeof(char),sizeof(char*)等得出

32位编译器

char :1个字节

char*(即指针变量): 4个字节(32位的寻址空间是2^32, 即32个bit,也就是4个字节。同理64位编译器)

short int : 2个字节

int:  4个字节

unsigned int : 4个字节

float:  4个字节

double:   8个字节

long:   4个字节

long long:  8个字节

unsigned long:  4个字节

 

64位编译器

char :1个字节

char*(即指针变量): 8个字节

short int : 2个字节

int:  4个字节

unsigned int : 4个字节

float:  4个字节

double:   8个字节

long:   8个字节

long long:  8个字节

unsigned long:  8个字节

32位,指针占用4个字节;
64位,指针占用8个字节。 

以下是实测结果:

#include <stdio.h> #include <limits.h>

int main(void) { printf("size of char %d\n",sizeof(char)); printf("size of char max %d\n",CHAR_MAX); printf("size of char min %d\n",CHAR_MIN); printf("size of int %d\n",sizeof(int)); printf("size of int min %d\n",INT_MIN); printf("size of int max %d\n",INT_MAX); printf("size of long %d\n",sizeof(long)); printf("size of long min %ld\n",LONG_MIN); printf("size of long max %ld\n",LONG_MAX); printf("size of short %d\n",sizeof(short)); printf("size of short min %d\n",SHRT_MIN); printf("size of short max %d\n",SHRT_MAX); printf("size of unsigned char %d\n",sizeof(unsigned char)); printf("size of unsigned char max %d\n",UCHAR_MAX); printf("size of unsigned long %d\n",sizeof(unsigned long)); printf("size of unsigned long max %lu\n",ULONG_MAX); printf("size of unsigned short %d\n",sizeof(unsigned short)); printf("size of unsigned short max %u\n",USHRT_MAX); printf("size of double %d\n",sizeof(double)); printf("size of long long %d\n",sizeof(long long)); printf("size of long double %d\n",sizeof(long double)); printf("size of float %d\n",sizeof(float)); int *p; printf("size of pointer  %d\n",sizeof(p)); } 64 |32位上运行结果:

 size of char 1 size of char max 127 size of char min -128 size of int 4 size of int min -2147483648 size of int max 2147483647 size of long 8  |32位是4 size of long min -9223372036854775808 size of long max 9223372036854775807 size of short 2 size of short min -32768 size of short max 32767 size of unsigned char 1 size of unsigned char max 255 size of unsigned long 8 |32位是4 size of unsigned long max 18446744073709551615 size of unsigned short 2 size of unsigned short max 65535 size of double 8 size of long long 8 size of long double 16  |32位是12 size of float 4 size of pointer  8  |32位是4 

 

Linux系统如何查看版本信息

  1. 输入"uname -a ",可显示电脑以及操作系统的相关信息。 

    Linux系统如何查看版本信息
  2. 输入"cat /proc/version",说明正在运行的内核版本。

    Linux系统如何查看版本信息
  3. 输入"cat /etc/issue", 显示的是发行版本信息

    Linux系统如何查看版本信息
  4. lsb_release -a (适用于所有的linux,包括Redhat、SuSE、Debian等发行版,但是在debian下要安装lsb)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值