program to find the size of primitive datatypes

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2008
Posts: 2
Reputation: thirtan is an unknown quantity at this point 
Solved Threads: 0
thirtan thirtan is offline Offline
Newbie Poster

program to find the size of primitive datatypes

 
0
  #1
Jun 12th, 2008
can anyone please help me write a program to find the size of primitve datatypes in a particular complier and display the same on the screen.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 351
Reputation: Radical Edward has a spectacular aura about Radical Edward has a spectacular aura about Radical Edward has a spectacular aura about 
Solved Threads: 62
Radical Edward's Avatar
Radical Edward Radical Edward is offline Offline
Posting Whiz

Re: program to find the size of primitive datatypes

 
0
  #2
Jun 12th, 2008
The result of the sizeof operator will give you the size in bytes. The result type is size_t, but printf doesn't support printing size_t except in C99. You can get around that by casting the result to the largest unsigned integer type, unsigned long:
  1. printf("Size of int (in bytes): %lu\n", (unsigned long)sizeof(int));
Rinse and repeat for every other type you want to display.
Last edited by Radical Edward; Jun 12th, 2008 at 2:12 pm.
If at first you don't succeed, keep on sucking until you do succeed.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 2
Reputation: thirtan is an unknown quantity at this point 
Solved Threads: 0
thirtan thirtan is offline Offline
Newbie Poster

Re: program to find the size of primitive datatypes

 
0
  #3
Jun 12th, 2008
thank u so much Edward
Last edited by thirtan; Jun 12th, 2008 at 2:30 pm. Reason: wrong spelling
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C Forum


Views: 850 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC