D
Donkey
Hello, I want to find out how many digits does each date type have and
how many bytes does it occupy in memory, so I wrote a program below:
#include <stdio.h>
const long double num=1123222.232121342;
main()
{
Printf("the number occupies: %i, and it is 1123222.232121342
\n",sizeof num);
printf("char: %i ,the number is %c\n",sizeof(char),(char)num);
printf("widechar: %i\n",sizeof(wchar_t));
printf("singed char: %i\n",sizeof(signed char));
printf("unsigned char: %i\n",sizeof(unsigned char));
printf("int: %i, the number is %i\n",sizeof(int),(int)num);
printf("long int: %i, the number is %li\n",sizeof(long int),(long
int)num);
printf("float: %i, the number is %f\n", sizeof(float),float(num));
printf("double: %i, the number is
%lf\n",sizeof(double),(double)num);
printf("long double: %i,the number is %Lf\n",sizeof(long
double),(long double)num);
printf("long long int: %i\n",sizeof(long long int));
printf("long long double: %i\n",sizeof(long long double));
}
But the execution result of the program is very surprising:
the number occupies: 12, and it is 1123222.232121342
char: 1 ,the number is
widechar: 2
singed char: 1
unsigned char: 1
int: 4, the number is 1123222
long int: 4, the number is 1123222
float: 4, the number is 1123222.250000
double: 8, the number is 1123222.232121
long double: 12,the number is -0.000000
long long int: 8
long long double: 8
You may notice that:
the memory occupied by int Date type and long int Date type is the
same,
print of long double number is not correct ,
and the memory long long double date type occupied is smaller (8 bytes)
than long double date type(12 bytes).
The Compiler I Use is GCC. The OS I use is Windows XP.
Can anyone tells me why do these problems happen?
Thanks a million.
how many bytes does it occupy in memory, so I wrote a program below:
#include <stdio.h>
const long double num=1123222.232121342;
main()
{
Printf("the number occupies: %i, and it is 1123222.232121342
\n",sizeof num);
printf("char: %i ,the number is %c\n",sizeof(char),(char)num);
printf("widechar: %i\n",sizeof(wchar_t));
printf("singed char: %i\n",sizeof(signed char));
printf("unsigned char: %i\n",sizeof(unsigned char));
printf("int: %i, the number is %i\n",sizeof(int),(int)num);
printf("long int: %i, the number is %li\n",sizeof(long int),(long
int)num);
printf("float: %i, the number is %f\n", sizeof(float),float(num));
printf("double: %i, the number is
%lf\n",sizeof(double),(double)num);
printf("long double: %i,the number is %Lf\n",sizeof(long
double),(long double)num);
printf("long long int: %i\n",sizeof(long long int));
printf("long long double: %i\n",sizeof(long long double));
}
But the execution result of the program is very surprising:
the number occupies: 12, and it is 1123222.232121342
char: 1 ,the number is
widechar: 2
singed char: 1
unsigned char: 1
int: 4, the number is 1123222
long int: 4, the number is 1123222
float: 4, the number is 1123222.250000
double: 8, the number is 1123222.232121
long double: 12,the number is -0.000000
long long int: 8
long long double: 8
You may notice that:
the memory occupied by int Date type and long int Date type is the
same,
print of long double number is not correct ,
and the memory long long double date type occupied is smaller (8 bytes)
than long double date type(12 bytes).
The Compiler I Use is GCC. The OS I use is Windows XP.
Can anyone tells me why do these problems happen?
Thanks a million.