How to get the number of bytes of a variable in C

1 Answer

0 votes
#include <stdio.h>

int main()
{
    char ch;
    size_t bytes = sizeof(ch);
    printf("%zu\n",bytes);
    
    int i;
    printf("%zu\n", sizeof(i));
    
    long l;
    printf("%zu\n", sizeof(l));
    
    float f;
    printf("%zu\n", sizeof(f));
    
    double d;
    printf("%zu\n", sizeof(d));

    return 0;
}



/*
run:

1
4
8
4
8

*/

 



answered Jun 3, 2025 by avibootz
edited Jun 3, 2025 by avibootz

Related questions

1 answer 228 views
1 answer 173 views
1 answer 179 views
1 answer 274 views
1 answer 202 views
1 answer 253 views
...