C PROGRAMMING PROGRAM • BASICS & INPUT/OUTPUT
Display the Size of C Data Types
Learn how to display the size of c data types using a clear C program.
PROBLEM UNDERSTANDING
Input and expected output
Sample input
No input required
Sample output
char: 1 byte(s) int: 4 byte(s) float: 4 byte(s) double: 8 byte(s)
COMPLETE C PROGRAM
Complete C implementation
#include <stdio.h>
int main(void)
{
printf("char: %zu byte(s)\n", sizeof(char));
printf("int: %zu byte(s)\n", sizeof(int));
printf("float: %zu byte(s)\n", sizeof(float));
printf("double: %zu byte(s)\n", sizeof(double));
return 0;
}CURRENT STEP
SELECTED LINE
EXPECTED OUTPUT FOR THE SAMPLE
char: 1 byte(s) int: 4 byte(s) float: 4 byte(s) double: 8 byte(s)
Step 0 of 0
PROGRAM EXPLANATION
Algorithm and explanation
- Read the required input values.
- Use sizeof to obtain the number of bytes reserved for each data type on the current platform.
- Display the computed result.
Use sizeof to obtain the number of bytes reserved for each data type on the current platform.
EFFICIENCY
Time and space complexity
Time complexity
O(1)
Auxiliary space
O(1)
DEBUGGING CHECKLIST
Common mistakes
Check this
Use the correct format specifier for every variable.
Check this
Initialize variables before using their values.
Check this
Check braces, semicolons and input order carefully.
Try it yourself
Practice: Run the program with the sample input, predict its output, and then test one boundary case of your own.
