C语言的基本数据类型(9)

C语言基本数据类型:通过一个程序来显示。我们可以通过调用sizeof()函数来查看其所占用的空间。字节数。1个字节为8位。

/************************************************************
 Copyright (C), 1998-2006, Rx. Co., Ltd.
 FileName: example.cpp
 Author: longronglin
 Version : 1.0
 Date: 2006-10-05
 Description:      
 Function List:   
    1. int main()
 History:      
      <author> <time> <version > <desc>
      longronglin    2006/10/05     1.0      modify xxx . 
**********************************************************
*/

#include 
"stdio.h"

/*
 * 返回1为正确执行
 
*/


int main()
{
    
int i;
    
short j;
    
long k;
    
float m;
    
double n;
    
char a;
    signed 
short int b;
    signed 
long int c;
    unsigned 
short int d;
    unsigned 
long int e;
    unsigned 
char f;
    signed 
char g;
    signed 
long int h;
    unsigned 
long int l;

    printf(
"the length of basic type  ");
    printf(
"the byte of int = %d  ",sizeof(i));
    printf(
"the byte of short = %d  ",sizeof(j));
    printf(
"the byte of long = %d  ",sizeof(k));
    printf(
"the byte of float = %d  ",sizeof(m));
    printf(
"the byte of double = %d  ",sizeof(n));
    printf(
"the byte of char = %d  ",sizeof(a));
    printf(
"the byte of signed short int = %d  ",sizeof(b));
    printf(
"the byte of signed long int = %d  ",sizeof(c));
    printf(
"the byte of unsigned short int = %d  ",sizeof(d));
    printf(
"the byte of unsigned long int = %d  ",sizeof(e));
    printf(
"the byte of unsigned char = %d  ",sizeof(f));
    printf(
"the byte of signed char = %d  ",sizeof(g));
    printf(
"the byte of signed long int = %d  ",sizeof(h));
    printf(
"the byte of unsigned long int = %d  ",sizeof(l));

    
return (1);
}
  

 运行结果:

下面的是美国标准:
在C语言中,一般int在复合定义时可以省略。比如long =long int。
当然编程时也可以使用如下语句查看类型所占字节数:printf("%d",sizeof(char))。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值