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

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了么。

相关推荐
zh路西法19 分钟前
【10天速通ROS2-PX4无人机】(四) 关掉GPS和气压计,纯激光定位还能飞吗
c++·无人机·px4·ros2·卡尔曼滤波·fastlio2
海天鹰43 分钟前
PHP上传文件
android·开发语言·php
yyds_yyd_100861 小时前
1464. 数组中两元素的最大乘积(2026.07.27)
数据结构·c++·算法·leetcode
Yeauty2 小时前
渲染成图再 CLI 拼接,还是进程内直推?Rust 帧到视频的两条路
开发语言·rust·音视频
geovindu3 小时前
CSharp: Breadth First Search Algorithm and Depth First Search Algorithm
开发语言·后端·算法·c#·.net·搜索算法
库克克3 小时前
【C++】set 与multiset
开发语言·c++
寒月小酒3 小时前
第五章 生成集成 和第六章 RAG评估(all-in-rag学习)
数据库·学习
Wang's Blog3 小时前
Go-Zero项目开发34: 微服务超时控制与重试机制实践
开发语言·微服务·golang·go-zero
魔城烟雨4 小时前
从零开始学习betaflight《5-坐标系》
学习
Mortalbreeze4 小时前
深入 Linux Socket 编程:端口号、网络字节序与 struct sockaddr 详解
linux·服务器·网络·c++