[C++]学习中的一个问题

#include<iostream>
#include<string>
#include<cstring>
using namespace std;

int main(){
    char str[31];
    cout << "--==--" << sizeof(str) << endl;
    // 给了
    memset(str, 0, sizeof(str));
    for (size_t i = 0; i < 31; i++)
    {
       cout << "qweqwe:" << i << " dd:" << (str[i]==0) <<"  ff:"<< str[i]<< endl;
    }
    cout << "-----------===========--" << str << endl;
    return 1;

在这里插入图片描述
为什么 == 0 是true,而打印出来没东西啊,是个初始化的问题,我不是
memset(str, 0, sizeof(str)); 把str的所有位置都置成0了么。

猜你喜欢

转载自blog.csdn.net/weixin_40293999/article/details/132548869