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
时间: 2024-10-20 04:33:40