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.

BeginnersizeofData typessize_t

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

size-of-data-types.c
Open in compiler
#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;
}

GUIDED CODE TOUR • NOT LIVE EXECUTION

Study the program line by line

Use the real compiler button above to run and debug with different inputs.

CURRENT STEP

Select Start to walk through the important lines.

SELECTED LINE

No line selected

EXPECTED OUTPUT FOR THE SAMPLE

char: 1 byte(s)
int: 4 byte(s)
float: 4 byte(s)
double: 8 byte(s)
0%Step 0 of 0

PROGRAM EXPLANATION

Algorithm and explanation

  1. Read the required input values.
  2. Use sizeof to obtain the number of bytes reserved for each data type on the current platform.
  3. 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.