其他分享
首页 > 其他分享> > C语言中输出不同变量类型的长度(单位为字节,1字节等于8位)

C语言中输出不同变量类型的长度(单位为字节,1字节等于8位)

作者:互联网

 

001、

c语言中将表示字符的char型的长度定义为1.

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


int main(void)
{
    printf("sizeof(char)   = %u\n", (unsigned)sizeof(char));
    printf("sizeof(short)  = %u\n", (unsigned)sizeof(short));
    printf("sizeof(int)    = %u\n", (unsigned)sizeof(int));
    printf("sizeof(long)   = %u\n", (unsigned)sizeof(long));
    
    printf("unsigned  char: %d-%d\n", 0, UCHAR_MAX);
    printf("unsigned short: %u-%u\n", 0, USHRT_MAX);
    printf("unsigned   int: %u-%u\n", 0, UINT_MAX);
    printf("unsigned  long: %lu-%lu\n", 0, ULONG_MAX);
    
    return 0;
}

 

 

标签:-%,字节,int,unsigned,C语言,char,printf,sizeof,变量
来源: https://www.cnblogs.com/liujiaxin2018/p/16586896.html