Re: Something About Date Type



Donkey wrote:
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:


Which ``date'' type are you talking about?

#include <stdio.h>
const long double num=1123222.232121342;
main()

int main (void) or
int main (int argc, char *argv[]) or
int main (int argc, char **argv).

Please read the newsgroup archive before posting code.

{
Printf("the number occupies: %i, and it is 1123222.232121342
\n",sizeof num);

Identifiers in C are case-sensitive. ``Printf'' is not the same as
``printf''

printf("char: %i ,the number is %c\n",sizeof(char),(char)num);

Loss of data. Why print a double value as a char?
sizeof evaluates to a value of type size_t. You can use
a cast to ``unsigned long'' here and %lu for the conversion
specifier.

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));
}

main returns int.


But the execution result of the program is very surprising:

Not really surprising.

<snip>


You may notice that:
the memory occupied by int Date type and long int Date type is the
same,

Again, which ``Date'' type? I don't see any such type in your code.

<snip>

Can anyone tells me why do these problems happen? Thanks a million.


They happen because you forget to read a good book on C.
Pick up K&R 2. :)


Regards,
Jonathan.

--
Meow!
.



Relevant Pages