test sizeof


点击(此处)折叠或打开

  1. #include <stdio.h>
  2. float mypower(int);

  3. int main(void){
  4.     char c;
  5.     short s;
  6.     int i;
  7.     long l;
  8.     unsigned u;
  9.     float f;
  10.     double d;
  11.     long double ld;
  12.     int a[20];
  13.     int *ptr = a;

  14.     printf("size of char is %d\t"
  15.         "the kinds of char is %0.f\n"
  16.         "size of short is %d\t"
  17.         "the kinds of short is %0.f\n"
  18.         "size of int is %d\t"
  19.         "the kinds of int is %0.f\n"
  20.         "size of long is %d\t"
  21.         "the kinds of long is %0.f\n"
  22.         "size of unsigned is %d\t"
  23.         "the kinds of unsigned is %0.f\n"
  24.         "size of float is %d\t"
  25.         "the kinds of float is %0.f\n"
  26.         "size of double is %d\t"
  27.         "the kinds of double is %0.f\n"
  28.         "size of long double is %d\t"
  29.         "the kinds of long double is %0.f\n"
  30.         "size of array is %d\t"
  31.         "the kinds of array is %0.f\n"
  32.         "size of pointer is %d\t"
  33.         "the kinds of pointer is %0.f\n",
  34.         sizeof(c), mypower(sizeof(c)),
  35.         sizeof(s), mypower(sizeof(s)),
  36.         sizeof(i), mypower(sizeof(i)),
  37.         sizeof(l), mypower(sizeof(l)),
  38.         sizeof(u), mypower(sizeof(u)),
  39.         sizeof(f), mypower(sizeof(f)),
  40.         sizeof(d), mypower(sizeof(d)),
  41.         sizeof(ld), mypower(sizeof(ld)),
  42.         sizeof(a), mypower(sizeof(a)),
  43.         sizeof(ptr)),mypower(sizeof(ptr));

  44.     return 0;
  45.     
  46. }

  47. float mypower(int x){
  48.     float base = 1.0;
  49.     for (int i = 1; i <= (8 * x); i++)
  50.     {
  51.         base = 2 * base;
  52.     }

  53.     return base;
  54. }

<script type=text/javascript charset=utf-8 src="http://static.bshare.cn/b/buttonLite.js#style=-1&uuid=&pophcol=3&lang=zh"></script> <script type=text/javascript charset=utf-8 src="http://static.bshare.cn/b/bshareC0.js"></script>
阅读(3) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值