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.

Recommended Answers

All 2 Replies

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. :)

thank u so much Edward

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.