954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

program to find the size of primitive datatypes

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.

thirtan
Newbie Poster
2 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
 

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:

printf("Size of int (in bytes): %lu\n", (unsigned long)sizeof(int));

Rinse and repeat for every other type you want to display. :)

Radical Edward
Posting Pro
545 posts since May 2008
Reputation Points: 361
Solved Threads: 97
 

thank u so much Edward

thirtan
Newbie Poster
2 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You