✓ Link copied to clipboard
C 📅 July 3, 2026 ⏱ 4 min read

C Program to Find the Size of int, float, double and char

C Program to Find the Size of int, float, double and char

When you’re working with C, knowing how much memory different data types use is super important. This program's gonna show you how to find the size of int, float, double, and char variables. It’s pretty simple but essential for managing memory.

Prerequisites for Finding Data Type Sizes in C

Before you begin, make sure you're familiar with:

  • The sizeof() operator in C
  • Basic C syntax and data types
  • Any C compiler such as GCC 9 or newer — or just run it in the EduSeekho online compiler

Source Code of C Program to Find the Size of int, float, double and char

Here's the complete C code to determine the size of these data types.

find_size.cC▶ Run
#include <stdio.h>

int main() {
    // Declare and print sizes of various data types
    printf("Size of int: %zu bytes\n", sizeof(int));
    printf("Size of float: %zu bytes\n", sizeof(float));
    printf("Size of double: %zu bytes\n", sizeof(double));
    printf("Size of char: %zu bytes\n", sizeof(char));
    return 0;
}

Try this code yourself — free

Run it in the EduSeekho online compiler. No setup needed.

▶ Open Compiler

Output of the Find Size of int, float, double and char Program

Run the program to see the memory usage for each data type.

OutputPlain Text▶ Run
Size of int: 4 bytes
Size of float: 4 bytes
Size of double: 8 bytes
Size of char: 1 byte
Output of C Program to Find the Size of int, float, double and char
Output of C Program to Find the Size of int, float, double and char

Algorithm to Find Data Type Sizes in C

This program uses the sizeof() operator to calculate the memory size of each data type, which is then printed out. Here's how the program does it:

  1. Declare the sizes of int, float, double, and char using the sizeof() operator.
  2. Print the size of each data type in bytes using printf.
flowchart TD
  A([Start]) --> B[Declare variables]
  B --> C[/Print size of int/]
  C --> D[/Print size of float/]
  D --> E[/Print size of double/]
  E --> F[/Print size of char/]
  F --> G([End])
Flowchart: the algorithm step by step

How the Size Finding Program Works

Let's break down the code to understand how it measures data type sizes.

  • #include <stdio.h>: This line includes the standard input-output library, which is necessary for the printf statement.
  • int main(): The main function where execution starts.
  • printf: Used to display the size of each data type, formatted using %zu for size_t, returned by sizeof.
  • sizeof(int), sizeof(float), sizeof(double), sizeof(char): These expressions return the size in bytes of the respective data types.
  • return 0;: Indicates that the program finished successfully.
🧠

Quick Quiz — test your understanding

Tap an option to check your answer

Which function is used to find the size of a data type in C?

🎉Correct! The sizeof() function returns the size of a data type in bytes.
🤔Not quite. Hint: It’s a built-in function in C that helps with memory calculations.

How Fast Is the Size Finding Program in C?

Understanding the time and space complexity gives us insight into the program’s efficiency.

Time Complexity: O(1). This program executes a fixed number of printf statements regardless of the input, making it constant time.

Space Complexity: O(1). The program uses only the memory required for four printf calls and no additional variables that grow with input.

⚠️

Common mistake: Assuming sizeof() gives the size in bits instead of bytes.

Key takeaway: Using sizeof() is a smart way to see how much memory different data types take up in C.

FAQs About Finding Data Type Sizes in C

Here are some common questions about the program:

The sizeof() operator helps you figure out how much memory different data types need, which is key for optimizing memory usage.
Yeah, sizes can differ on various systems or compilers, though you often see common sizes in modern setups.
Nope, sizeof() doesn’t evaluate the expression. It just returns the size of the data type.
sizeof is an operator in C, not a function. Simple as that.
Absolutely, it can also determine the size of custom data types like structs.

If you found this program helpful, check out these related programs:

Conclusion

Now you’ve seen how handy the sizeof() operator is for understanding memory usage in C. Try playing around with other data types or custom structures. It'll really boost your knowledge of memory. Keep practicing!

Test your skills with our C programming quiz or dive deeper with the EduSeekho online compiler.