C数据类型大小 [英] c data type size

查看:180
本文介绍了C数据类型大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能知道所有数据类型的大小在我的电脑?

How i can know the size of all data type in my computer?

推荐答案

下面的程序应该做的伎俩为基本类型:

The following program should do the trick for the primitive types:

#include <stdio.h>
int main()
{
    printf("sizeof(char) = %d\n", sizeof(char));
    printf("sizeof(short) = %d\n", sizeof(short));
    printf("sizeof(int) = %d\n", sizeof(int));
    printf("sizeof(long) = %d\n", sizeof(long));
    printf("sizeof(long long) = %d\n", sizeof(long long));
    printf("sizeof(float) = %d\n", sizeof(float));
    printf("sizeof(double) = %d\n", sizeof(double));
    printf("sizeof(long double) = %d\n", sizeof(long double));
}

这定义打印的sizeof(char)的== 1 的类型使用的字节数与。正是1的装置(即这是多少比特)是实施方式特定的,并可能取决于底层硬件上。一些机器具有例如7位字节,有的有10或12位字节。

This prints the number of "bytes" the type uses, with sizeof(char) == 1 by definition. Just what 1 means (that is how many bits that is) is implementation specific and likely depend on the underlying hardware. Some machines have 7 bit bytes for instance, some have 10 or 12 bit bytes.

这篇关于C数据类型大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆