c - Why do I have to use %ld when referring to the size of an int variable? -
i define int this:
int a;
when want lookup size of int, have use format specifier %ld this:
printf("int size %ld\n", sizeof(a));
when use %d format specifier, following error:
foo.c:7:10: warning: format ‘%d’ expects argument of type ‘int’, argument 2 has type ‘long unsigned int’ [-wformat=] printf("int size %d\n", sizeof(a));
the question is, why result of sizeof() defined long unsigned int when parameter of function int?
the type of sizeof(anything)
size_t
, unsigned integral constant. print it, should using %zu
.
Comments
Post a Comment