Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,945 questions

51,887 answers

573 users

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 134 views
1 answer 182 views
182 views asked Jan 18, 2017 by avibootz
1 answer 181 views
1 answer 249 views
1 answer 184 views
1 answer 155 views
...