Algorithm


Determine and Display Sizes of Data Types

1. Input:
No explicit input is required as the code focuses on determining the sizes of predefined data types.

2. Variable Declaration:
Declare variables of different data types: intType (int), floatType (float), doubleType (double), and charType (char).

3. Size Calculation and Display:
Use the sizeof operator to calculate the size (in bytes) of each variable.
Print the size of each variable using the printf function, indicating the data type and size.

Code Examples

#1 Example Program to Find the Size of Variables

Code - C Programming

#include<stdio.h>
int main() {
    int intType;
    float floatType;
    double doubleType;
    char charType;

    // sizeof evaluates the size of a variable
    printf("Size of int: %zu bytes\n", sizeof(intType));
    printf("Size of float: %zu bytes\n", sizeof(floatType));
    printf("Size of double: %zu bytes\n", sizeof(doubleType));
    printf("Size of char: %zu byte\n", sizeof(charType));
    
    return 0;
}
Copy The Code & Try With Live Editor

Output

x
+
cmd
Size of int: 4 bytes
Size of float: 4 bytes
Size of double: 8 bytes
Size of char: 1 byte
Advertisements

Demonstration


C Programing Example to Find the Size of int, float, double and char-DevsEnv

Next
Appending into a File in C Programming