473,763 Members | 5,610 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Something About Date Type

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.232 121342;
main()
{
Printf("the number occupies: %i, and it is 1123222.2321213 42
\n",sizeof num);
printf("char: %i ,the number is %c\n",sizeof(ch ar),(char)num);
printf("widecha r: %i\n",sizeof(wc har_t));
printf("singed char: %i\n",sizeof(si gned char));
printf("unsigne d char: %i\n",sizeof(un signed char));
printf("int: %i, the number is %i\n",sizeof(in t),(int)num);
printf("long int: %i, the number is %li\n",sizeof(l ong int),(long
int)num);
printf("float: %i, the number is %f\n", sizeof(float),f loat(num));
printf("double: %i, the number is
%lf\n",sizeof(d ouble),(double) num);
printf("long double: %i,the number is %Lf\n",sizeof(l ong
double),(long double)num);
printf("long long int: %i\n",sizeof(lo ng long int));
printf("long long double: %i\n",sizeof(lo ng long double));
}

But the execution result of the program is very surprising:

the number occupies: 12, and it is 1123222.2321213 42
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.

Mar 31 '06 #1
5 2406
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.232 121342;
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.2321213 42
\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(ch ar),(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("widecha r: %i\n",sizeof(wc har_t));
printf("singed char: %i\n",sizeof(si gned char));
printf("unsigne d char: %i\n",sizeof(un signed char));
printf("int: %i, the number is %i\n",sizeof(in t),(int)num);
printf("long int: %i, the number is %li\n",sizeof(l ong int),(long
int)num);
printf("float: %i, the number is %f\n", sizeof(float),f loat(num));
printf("double: %i, the number is
%lf\n",sizeof(d ouble),(double) num);
printf("long double: %i,the number is %Lf\n",sizeof(l ong
double),(long double)num);
printf("long long int: %i\n",sizeof(lo ng long int));
printf("long long double: %i\n",sizeof(lo ng 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!
Mar 31 '06 #2
"Donkey" <ne********@hot mail.com> writes:
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.232 121342;
main()
This should be "int main(void)".
{
Printf("the number occupies: %i, and it is 1123222.2321213 42\n",sizeof num);
printf, not Printf.

The "%i" format expects an int. sizeof yields a size_t.

To print the result of sizeof, convert it to unsigned long -- or use
"%zu" if your runtime library supports it (it's new in C99). For
example:

printf("sizeof num = %ld\n", (unsigned long)sizeof num);
printf("char: %i ,the number is %c\n",sizeof(ch ar),(char)num);
printf("widecha r: %i\n",sizeof(wc har_t));
printf("singed char: %i\n",sizeof(si gned char));
printf("unsigne d char: %i\n",sizeof(un signed char));
printf("int: %i, the number is %i\n",sizeof(in t),(int)num);
printf("long int: %i, the number is %li\n",sizeof(l ong int),(long int)num);
printf("float: %i, the number is %f\n", sizeof(float),f loat(num));
float(num) is a syntax error; you mean (float)num.
printf("double: %i, the number is %lf\n",sizeof(d ouble),(double) num);
printf("long double: %i,the number is %Lf\n",sizeof(l ong double),(long double)num);
printf("long long int: %i\n",sizeof(lo ng long int));
printf("long long double: %i\n",sizeof(lo ng long double));
There is no "long long double" in standard C.
}
The code you posted isn't the code you compiled (unless your compiler
is entirely too forgiving). It would also be helpful if you kept your
line length down.
But the execution result of the program is very surprising:

the number occupies: 12, and it is 1123222.2321213 42
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.


It's not uncommon for types int and long int to be the same size.

Possibly your runtime library (which is separate from your compiler)
doesn't handle "%Lf" properly.

Recent versions of gcc properly reject "long long double". A buggy
old version treats it as "long long".

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 31 '06 #3
Jonathan Burd <jb@nomail.co m> writes:
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?


Perhaps it was a typo for "data type".

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 31 '06 #4
Groovy hepcat Keith Thompson was jivin' on Fri, 31 Mar 2006 06:17:34
GMT in comp.lang.c.
Re: Something About Date Type's a cool scene! Dig it!
To print the result of sizeof, convert it to unsigned long -- or use
"%zu" if your runtime library supports it (it's new in C99). For
example:

printf("sizeof num = %ld\n", (unsigned long)sizeof num);


No doubt Keith means this. (Note the %lu conversion specifier):

printf("sizeof num = %lu\n", (unsigned long)sizeof num);

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technicall y correct" English; but since when was rock & roll "technicall y correct"?
Apr 3 '06 #5
ph******@alphal ink.com.au.NO.S PAM (Peter "Shaggy" Haywood) writes:
Groovy hepcat Keith Thompson was jivin' on Fri, 31 Mar 2006 06:17:34
GMT in comp.lang.c.
Re: Something About Date Type's a cool scene! Dig it!
To print the result of sizeof, convert it to unsigned long -- or use
"%zu" if your runtime library supports it (it's new in C99). For
example:

printf("sizeof num = %ld\n", (unsigned long)sizeof num);


No doubt Keith means this. (Note the %lu conversion specifier):

printf("sizeof num = %lu\n", (unsigned long)sizeof num);


Yes, thanks for the correction.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Apr 3 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3735
by: Dominique Javet | last post by:
Hello, I'm new to php and mysql and I use Dreamweaver MX 2004, so sorry for this "newbie" question... I've found no answer in the forum ... I've a date problem with my formular. In my mysql DB my filed "date" in table "experience" is like this: Y-m-d (2002-07-23). My fied`date` is date, NOT NULL with no default entry My form read well the date data depending the id, (pe. 30.02.2003), but when I submit a new date, I receive as result...
21
1940
by: Samir | last post by:
Say I put a date and time for like this: Jun-15-04 21:52:06 Here is the form I am using: <form> <p><input type="text" name="T1" size="20"><br> date</p> <p><input type="text" name="T2" size="20"><br> 90 days from date</p> <p><input type="submit" value="Submit" name="B1"></p>
8
25389
by: dlx_son | last post by:
Here is the code so far <form name="thisform"> <h3>Enter time to add to or subtract from:</h3> (If not entered, current time will be used)<br> Day: <input name="d1" alt="Day of month" size=3> Month: <input name="m1" alt="Month" size=3> Year: <input name="y1" alt="Year" size=5> (4 digits for year, e.g.
2
2304
by: BlackFireNova | last post by:
I have an Access 2003 mdb which contains software records. I need to sort on a particular type of software, and then identify and count how many copies there are per each group of that type purchased on the same date. I have no trouble doing a query to extract the type (say MS Excel 2002, for example). The trouble is, there could be 50 copies purchased on date "x", 80 copies purchased on date "y", and 250 copies purchased on date "z",...
0
2722
by: oneplace | last post by:
I have the following script that use for the following after i have made my search for a name in my database. I select the name and it bring up this from with all the information of the person. It works great up to the point of the date entries. It will bring up the fromat date ok, but when I try and change it and head the submit buton it wipes out the database information. The database stores the information like yyyy-mm-dd hh:mm:ss. I have it...
5
3231
by: bruce24444 | last post by:
I have a database which assigns warranty claims to people with a main screen showing number of files assigned to each person. The number assigned shows day, week, month and year numbers so they can be evenly distributed. The problem I'm having is getting the query to return a number of files for the current date. Week, month and year appear to work fine. Below are the SQL's for both day and week. Any suggestions as to what's wrong...
4
7417
by: anagai | last post by:
I just want to check if a date entered in a textbox is equal to the current system date. I set the date object from the input field like this: dt1=new Date('10/01/2007'); the current system date is retrieved like this: curDt = new Date();
2
2893
by: ruraldev | last post by:
I have been trying my best to display a chosen date as dd-mm-yyyy but insert it into the mysql database as yyyy-mm-dd, I know it must be simple but no matter what I try I can't get it to work. Code: <?php require_once('../Connections/wind.php'); ?> <?php function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
3
5192
by: aRTx | last post by:
I have try a couple of time but does not work for me My files everytime are sortet by NAME. I want to Sort my files by Date-desc. Can anyone help me to do it? The Script <? /* ORIGJINALI
0
9563
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9822
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8821
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7366
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3522
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.