I am write my code on linux and use gcc compiler.
#include <stdio.h>
void main () {
printf("Data Types Size(bytes)\n");
printf("=======================================\n");
printf("char %2d\n", sizeof(char));
printf("unsigned char %2d\n", sizeof(unsigned char));
printf("signed char %2d\n", sizeof(signed char));
printf("int %2d\n", sizeof(int));
printf("unsigned int %2d\n", sizeof(unsigned int));
printf("unsigned long int %2d\n", sizeof(unsigned long int));
printf("unsigned short int %2d\n", sizeof(unsigned short int));
printf("signed int %2d\n", sizeof(signed int));
printf("short int %2d\n", sizeof(short int));
printf("signed short int %2d\n", sizeof(signed short int));
printf("long int %2d\n", sizeof(long int));
printf("signed long int %2d\n", sizeof(signed long int));
printf("float %2d\n", sizeof(float));
printf("double %2d\n", sizeof(double));
printf("long double %2d\n", sizeof(long double));
}
then compiled it show crash detected.
sizeof
yields a result of type size_t
, You must use %zu
format specifier to print the result.
Using mismatched type of arguments, (ex: %d
which expects an int
with result of sizeof
which needs a %zu
) invokes undefined behavior.
After that, void main ()
is a pretty obsolete signature for a hosted environment, you should at at least use int main (void)
to be conforming.
That said, I believe, your program did not crash, you did not run the binary, you were just in process of compiling that and the compiler has emitted warnings for your own good. Thanks for not ignoring them.