变量的指针和cout地址
Pointers and cout address of a variable
我正在尝试计算变量abc的地址,而程序刚好使崩溃
int main()
{
int *app;
int abc = 2;
*app=3;
cout << *app << endl << &*app << endl << abc;
cout << &abc;
}
然而,如果我删除地址变量int*app,那么它将定制abc 的地址
int main()
{
int abc = 2;
cout << &abc;
}
我不知道为什么另一个不相关的地址变量的存在会影响它。请告知。
问题就在这里:
*app=3;
这可能会导致分段错误,未定义的行为。
如果删除它,则可以看到预期的输出。
你想做什么??这是未定义的行为。
int *app; // pointer is not initialized.
int abc = 2;
*app=3; // de-referencing an uninitialized pointer. Bad.
相关文章:
- 将数组的地址分配给变量并删除
- 空基优化子对象的地址
- C++ 指针的内存地址和指向数组的内存地址如何相同?
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 在C++中打印指向不同基元数据类型的指针的内存地址
- std::cout.imbue()多重调用
- 如何在c++程序中找到函数的地址
- cout 打印内存地址而不是值
- 为什么取消引用的指针指向指针的 std::cout 会导致 -fsanitize=地址投诉?
- 为什么cout输出内存地址不是字符串?
- 为什么调用 cout.operator<<(const char*) 打印地址而不是字符串? 如何创建一个函数本地静态"HashSet<char>"并初始化它一次?
- cout矢量地址
- 使用cout,如何将char转换为变量的地址/引用(?)
- 变量的指针和cout地址
- 为什么 printf() 在指针中显示与 cout 不同的地址输出C++
- 使用 cout 打印对象指针值时地址长度不同
- 为什么将字符指针流式传输到 cout 不打印地址
- Std::getline()使用cout时返回内存地址
- 我们可以说cout只打印变量的第一个地址吗
- LPWSTR在cout中作为地址打印