小编Yum*_*514的帖子

打印尺寸类型:C

我想要打印

"(类型)的大小是(类型的大小)字节"
例如

"int的大小是4Byte"
由下面的代码.但是它说
"int的大小是8Byte"
我认为这段代码显示了string(int)的大小,但是int类型.我怎么解决这个问题?

#include <stdio.h>
char *variabletype[] = {"char", "unsigned char", "signed char", "int", "unsigned int", "short", "unsigned short", "long", "unsigned long", "long long", "unsigned long long"};

int main() {
    for (int i = 0; i < 11;++i) {
        printf("Size of %s is %u\n",variabletype[i], (unsigned int)(sizeof(variabletype[i])));
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

返回

Size of char is 8Byte
Size of unsigned char is 8Byte
Size of signed char is 8Byte
Size of int is 8Byte
Size of …
Run Code Online (Sandbox Code Playgroud)

c

3
推荐指数
1
解决办法
170
查看次数

标签 统计

c ×1