结构变量查询
Struct Variable Query
#include<bits/stdc++.h>
using namespace std;
typedef struct trie
{
int arr[26];
bool isleaf;
trie(int isleaf)
{
this->isleaf=9;
cout<<isleaf<<endl;
isleaf=false;
cout<<isleaf<<endl;
cout<<this->isleaf<<endl;
}
}* tr;
//void inser(s)
int main()
{
tr k=new trie(3);
cout<<k->isleaf;
}
工作正常,输出
3
0
1
1
但在
#include<bits/stdc++.h>
using namespace std;
typedef struct trie
{
int arr[26];
bool isleaf;
trie(int isleaf)
{
cout<<isleaf<<endl;
isleaf=false;
cout<<isleaf<<endl;
cout<<this->isleaf<<endl;
}
}* tr;
//void inser(s)
int main()
{
tr k=new trie(3);
cout<<k->isleaf;
}
我得到
3
0
68
68
我知道它未初始化,但为什么是 68?
如果在全局或内部函数中使用普通布尔值并在不初始化的情况下打印它 i 得到 0,那为什么不在这里呢?
并且有人也可以指出一些很好的来源来消除对此类变量声明,公共和私有概念,OOPS,结构和类之间的差异等的疑问。
[basic.fundamental]/6类型
bool
的值要么是true
要么是false
。49脚注49)以本国际标准描述为"未定义"的方式使用
bool
值,例如通过检查未初始化的自动对象的值,可能会导致其行为好像既不true
也不false
。
未定义的行为是未定义的。这就是它的长短。讨论为什么一个表现出未定义行为的程序碰巧以特定的方式表现出来,这真的是毫无意义的。
相关文章:
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- 将成员变量添加到共享库中的类中,不会破坏二进制兼容性吗
- Mongodb c++驱动程序:如何查询元素的数组
- 将数组的地址分配给变量并删除
- 为"adjacent"变量赋值时出现问题
- 结构变量查询
- 快速JSON如何使用字符串变量查询对象
- 带变量的 SQL 查询
- 如何在C 中的查询中传递变量
- 将变量插入到 SQLite 查询
- 查询特定变量的对齐方式
- 在MSSQL查询中使用C++变量
- 在 c++ 中使用"char*"变量进行查询
- 查询全局变量的初始化
- 如何使用本地变量作为MySQL查询的一部分(Qt c++)
- 查询类的静态成员变量
- 用查询中的变量替换表名
- c++和MySQL -如何在我的查询中包含变量
- 如何在c++中执行SQL查询来定义变量
- 在C语言中使用查询变量的SQL语句