关于sizeof和size_t再次置顶
关于sizeof和size_t再次置顶// sizeof.c -- uses sizeof operator
// uses C99 %z modifier -- try %u or %lu if you lack %zd
#include <stdio.h>
int main(void)
{
int n = 0;
size_t intsize;
intsize = sizeof (int);
printf("n = %d, n has %u bytes; all ints have %u bytes.\n",
n, sizeof n, intsize );
return 0;
}
结果:n=0, n has 2 bytes; all ints have 2 bytes.
修改后:
// sizeof.c -- uses sizeof operator
// uses C99 %z modifier -- try %u or %lu if you lack %zd
#include <stdio.h>
int main(void)
{
int n = 0;
size_t intsize;
intsize = sizeof (int);
printf("n = %d, n has %u bytes; all ints have %u bytes.\n",
n, sizeof n, intsize );
return 0;
}
结果:n=0, n has 0 bytes; all ints have 4 bytes.
为什么“n has 0 bytes”?