Display the sizes and ranges for each of C's data types
C Basic Declarations and Expressions: Exercise-86 with Solution
Write a C program to display the sizes and ranges for each of C's data types.
Sample Solution:
C Code:
#include <stdio.h> // Include standard input/output header file
#include <stdint.h> // Include header for fixed-size integer types
#include <inttypes.h> // Include header for format specifiers for integer types
int main( void )
{
printf( "Size of C data types:\n\n" ); // Print title
printf( "Type Bytes\n\n" ); // Print column headers
printf( "--------------------------------\n"); // Print separator line
// Print size of various data types
printf( "char %lu\n" , sizeof( char ) );
printf( "int8_t %lu\n" , sizeof( int8_t ) );
printf( "unsigned char %lu\n" , sizeof( unsigned char ) );
printf( "uint8_t %lu\n" , sizeof( uint8_t ) );
printf( "short %lu\n" , sizeof( short ) );
printf( "int16_t %lu\n" , sizeof( int16_t ) );
printf( "uint16t %lu\n" , sizeof( uint16_t ) );
printf( "int %lu\n" , sizeof( int ) );
printf( "unsigned %lu\n" , sizeof( unsigned ) );
printf( "long %lu\n" , sizeof( long ) );
printf( "unsigned long %lu\n" , sizeof( unsigned long ) );
printf( "int32_t %lu\n" , sizeof( int32_t ) );
printf( "uint32_t %lu\n" , sizeof( uint32_t ) );
printf( "long long %lu\n" , sizeof( long long ) );
printf( "int64_t %lu\n" , sizeof( int64_t ) );
printf( "unsigned long long %lu\n" , sizeof( unsigned long long ) );
printf( "uint64_t %lu\n" , sizeof( uint64_t ) );
printf( "float %lu\n" , sizeof( float ) );
printf( "double %lu\n" , sizeof( double ) );
printf( "long double %lu\n" , sizeof( long double ) );
printf( "_Bool %lu\n" , sizeof( _Bool ) );
printf( "\n" );
return 0; // Indicate successful execution of the program
}
Sample Output:
Size of C data types: Type Bytes -------------------------------- char 1 int8_t 1 unsigned char 1 uint8_t 1 short 2 int16_t 2 uint16t 2 int 4 unsigned 4 long 8 unsigned long 8 int32_t 4 uint32_t 4 long long 8 int64_t 8 unsigned long long 8 uint64_t 8 float 4 double 8 long double 16 _Bool 1
Flowchart:

C programming Code Editor:
Previous:Write a C program to print a table of all the Roman numeral equivalents of the decimal numbers in the range 1 to 50.
Next:Write a C program to display the minimum and maximum values for each of C's data types.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join