How to find the size of built-in data types in C

1 Answer

0 votes
#include <stdio.h>

int main()
{
    char ch = 'a';
    int n = 893;

    printf("Size of variable ch = %zu byte\n", sizeof(ch));
    printf("Size of variable n = %zu bytes\n", sizeof(n));

    printf("Size of char = %zu bytes\n", sizeof(char));
    printf("Size of short = %zu bytes\n", sizeof(short));
    printf("Size of int = %zu bytes\n", sizeof(int));
    printf("Size of long = %zu bytes\n", sizeof(long));
    printf("Size of float = %zu bytes\n", sizeof(float));
    printf("Size of double = %zu bytes\n", sizeof(double));
    printf("Size of long double = %zu bytes\n", sizeof(long double));
    printf("Size of void = %zu bytes\n", sizeof(void));

    return 0;
}
 
 
 
 
/*
run:
    
Size of variable ch = 1 byte
Size of variable n = 4 bytes
Size of char = 1 bytes
Size of short = 2 bytes
Size of int = 4 bytes
Size of long = 8 bytes
Size of float = 4 bytes
Size of double = 8 bytes
Size of long double = 16 bytes
Size of void = 1 bytes

*/

 



answered Sep 17, 2021 by avibootz

Related questions

1 answer 148 views
1 answer 193 views
193 views asked Jan 18, 2017 by avibootz
1 answer 221 views
1 answer 279 views
1 answer 202 views
1 answer 172 views
...