[C] sizeof

#include <stdio.h>

int main(void)
{
        puts("------------------------------");
        puts(" ** Size of data type ** ");
        puts("------------------------------");

        printf(" char = %d byte \n", sizeof(char));
        puts("------------------------------");

        printf(" short = %d byte \n", sizeof(short));
        puts("------------------------------");

        printf(" int = %d byte \n", sizeof(int));
        puts("------------------------------");

        printf(" long = %d byte \n", sizeof(long));
        puts("------------------------------");

        printf(" float = %d byte \n", sizeof(float));
        puts("------------------------------");

        printf(" double = %d byte \n", sizeof(double));
        puts("------------------------------");

        return 0;

        /*
        ------------------------------
         ** Size of data type **
        ------------------------------
         char = 1 byte
        ------------------------------
         short = 2 byte
        ------------------------------
         int = 4 byte
        ------------------------------
         long = 4 byte
        ------------------------------
         float = 4 byte
        ------------------------------
         double = 8 byte
        ------------------------------
        */
}
#include <stdio.h>

int main(void)
{
        printf(" 'A' = %d byte \n", sizeof('A'));
        puts("------------------------------");

        printf(" 50 = %d byte \n", sizeof(50));
        puts("------------------------------");

        printf(" 3.15 = %d byte \n", sizeof(3.15));
        puts("------------------------------");

        printf(" \"programming\" = %d byte \n", sizeof("programming"));
        puts("------------------------------");

        return 0;

        /*
         'A' = 4 byte
        ------------------------------
         50 = 4 byte
        ------------------------------
         3.15 = 8 byte
        ------------------------------
         "programming" = 12 byte
        ------------------------------
        */
}

Reference

Tags:

Categories:

Updated: