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
#include
#include
int main( void )
{
printf( "Size of C data types:\n\n" );
printf( "Type Bytes\n\n" );
printf( "--------------------------------\n");
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;
}
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:
Contribute your code and comments through Disqus.
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.
C Programming: Tips of the Day
Static variable inside of a function in C
The scope of variable is where the variable name can be seen. Here, x is visible only inside function foo().
The lifetime of a variable is the period over which it exists. If x were defined without the keyword static, the lifetime would be from the entry into foo() to the return from foo(); so it would be re-initialized to 5 on every call.
The keyword static acts to extend the lifetime of a variable to the lifetime of the programme; e.g. initialization occurs once and once only and then the variable retains its value - whatever it has come to be - over all future calls to foo().
Ref : https://bit.ly/3fOq7XP
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework