码迷,mamicode.com
首页 > 其他好文 > 详细

关于数据类型的一些测试

时间:2015-05-22 22:26:33      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <stdlib.h>
 4 #include <string.h>
 5 using namespace std;
 6 #define M 200 + 10
 7 int main()
 8 {
 9     printf("Data type               number of bytes\n");
10     printf("---------               ---------------\n");
11     printf("short int               \t%d\n",sizeof(short int));
12     printf("int                     \t%d\n",sizeof(int));
13     printf("unsigned int            \t%d\n",sizeof(unsigned int));
14     printf("long int                \t%d\n",sizeof(long int ));
15     printf("unsigned long int       \t%d\n",sizeof(unsigned long int));
16     printf("long long int           \t%d\n",sizeof(long long int));
17     printf("unsigned long long int  \t%d\n",sizeof(unsigned long long int));
18     printf("float                   \t%d\n",sizeof(float));
19     printf("double                  \t%d\n",sizeof(double));
20     printf("long double             \t%d\n",sizeof(long double));
21     printf("char                    \t%d\n",sizeof(char));
22     printf("unsigned char           \t%d\n",sizeof(unsigned char));
23     return 0;
24 }

运行结果:

Data type number of bytes
--------- ---------------
short int 2
int 4
unsigned int 4
long int 4
unsigned long int 4
long long int 8
unsigned long long int 8
float 4
double 8
long double 12
char 1
unsigned char 1

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <stdlib.h>
 4 #include <string.h>
 5 using namespace std;
 6 int main()
 7 {
 8     unsigned long long int a = 1;
 9     int n = 100;
10     for(int i = 0;i <= n;i ++)
11     {
12         printf("%I64u\t%I64u\t%d\n",a - 1,a,i);
13         a = a * 2;
14     }
15 }

unsigned int 0~4294967295  0~2^32 %u

int -2147483648~2147483647    -2^31~2^31-1

long long int -9223372036854775808~9223372036854775807  -2^63~2^63-1

unsigned long long int 0~18446744073709551615         0~2^64  %I64u

关于数据类型的一些测试

标签:

原文地址:http://www.cnblogs.com/zouqihan/p/4523327.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!