C Program to Find the Size of int, float, double and char
                                        
                                                                                    
                                                
                                                    Last Updated : 
                                                    23 Jul, 2025
                                                
                                                 
                                                 
                                             
                                                                             
                                                             
                            
                            
                                                                                    
                Write a C program to find the size of the data types: int, float, double, and char in bytes and print it on the output screen.
Examples
Input: char
Output: Size of char: 1 byte
Input: int
Output:Size of int: 4 bytes
Different Methods to Find the Size of int, float, double and char in C
We can find the size of the int, float, double and char data types using many different methods available in C:
1. Using sizeof() Operator Directly
In C, we have sizeof() operator that can find the size of the data type that is provided as the argument. We can use this operator to find the size of int, char, float and double by passing them as parameters.
Syntax of sizeof()
sizeof(data_type);
Implementation
The below program uses the sizeof operator on the data type directly to find its size of it in bytes
            C
    // C Program to Find the Size of int, float, double, and
// char using sizeof operator directly
#include <stdio.h>
int main() {
  
    // Determine and Print the size of int
    printf("Size of int: %u bytes\n", sizeof(int));
    // Determine and Print the size of float
    printf("Size of float: %u bytes\n", sizeof(float));
    // Determine and Print the size of double
    printf("Size of double: %u bytes\n", sizeof(double));
    // Determine and Print the size of char
    printf("Size of char: %u bytes\n", sizeof(char));
    return 0;
}
OutputSize of int: 4 bytes
Size of float: 4 bytes
Size of double: 8 bytes
Size of char: 1 bytes
 Time Complexity: O(1)
Aulixiary Space: O(1)
2. Using sizeof Operator on Variables
The sizeof operator does not only works on the data types, but also on the variables of these data types. We just need to pass the variable name instead of type.
Implementation
The below program uses the sizeof operator on the variable of a data type to find its size of it in bytes
            C
    // C program to find the size of int, char,
// float and double data types
#include <stdio.h>
int main() {
  
  	// Variables of int, char, float and double
    int integerType;
    char charType;
    float floatType;
    double doubleType;
    // Determine and Print  the size of integer type
    printf("Size of int is: %u bytes", sizeof(integerType));
    // Determine and Print the size of floatType
    printf("\nSize of float is: %u bytes", sizeof(floatType));
    // Determine and Print the size of doubleType
    printf("\nSize of double is: %u bytes", sizeof(doubleType));
    // Determine and Print the size of charType
    printf("\nSize of char is: %u bytes", sizeof(charType));
    return 0;
}
OutputSize of int is: 4 bytes
Size of float is: 4 bytes
Size of double is: 8 bytes
Size of char is: 1 bytes
 Time Complexity: O(1)
Aulixiary Space: O(1)
3. Using Pointers
In C, when you increment or decrement a pointer, the address changes based on the size of the data type it points to, not just by 1. For example, a pointer to integer stores address: 0x12fb1 will not simply increase to 0x12fb2 after incrementing, it will be 0x12fb5 accounting for the size of the integer.
So, the idea is to store this pointer as integer and find the difference between the memory addresses to find the size in bytes.
Note: This method only works if the system is byte addressable.
Implementation
The below program implements the above approach:
            C
    // C program to find the size of given data type using pointers
#include <stdio.h>
int main() {
    int intType;
    // Pointer to the variable of type int
    int *ptr = &intType;
    // Converting the pointer to the long long unsigned int value
    unsigned long long start = (unsigned long long )ptr;
  	// Incrementing and converting it again
    ptr++;
    unsigned long long end = (unsigned long long)ptr;
    // Find the difference/size
    unsigned long long size = (unsigned long long)(end - start);
    printf("Size of int is: %llu bytes", size);
    return 0;
}
OutputSize of int is: 4 bytes
 Time Complexity: O(1)
Aulixiary Space: O(1)
                                
                                
                            
                                                                                
                                                            
                                                    
                                                
                                                        
                            
                        
                                                
                        
                                                                                    
                                                                Explore
                                    
                                        C Basics
Arrays & Strings
Pointers and Structures
Memory Management
File & Error Handling
Advanced Concepts