为什么布尔数组的int类型输出不是1或0?

问题描述

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

int main(void) {
    char ch[] = "test";
    bool X[32];
    char * pos = (char *)X;
    for (int i = 0; i < 4; ++i) {
        pos[i] = ch[i];
    }
    printf("%d\n",X[0]);
    return 0;
}

输出: 116

数组中都有int类型的数字,它们不是1或0,并且布尔类型是'false'。

如下图。

VS代码调试: enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)