这个野指针不?为什么可以使用?

方紫涵 方紫涵 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

#include<iostream>
#include<cstring>

using namespace std;

class A
{
public:
void prinfs()
{
cout<<"aaaaa"<<endl;
}
};



int main( )
{
A *a;
a->prinfs();
return 0;
}


A *a;
a->prinfs(); //这个a是个野指针不?为什么能够执行阿?

在g++里面

work/ctest$ g++ array.cpp -o 1
/work/ctest$ ./1
aaaaa
...全文

相关推荐

N.Parlante(Stanford2000)指针与内存

斯坦福大学的学习资料 Pointers — Before and After There's a lot of nice, tidy code you can write without knowing about pointers. But once you learn to use the power of pointers, you can never go back. There are too many things that can only be done with pointers. But with increased power comes increased responsibility. Pointers allow new and more ugly types of bugs, and pointer bugs can crash in random ways which makes them more difficult to debug. Nonetheless, even with their problems, pointers are an irresistibly powerful programming construct. (The following explanation uses the C language syntax where a syntax is required; there is a discussion of Java at the section.) Why Have Pointers? Pointers solve two common software problems. First, pointers allow different sections of code to share information easily. You can get the same effect by copying information back and forth, but pointers solve the problem better. Second, pointers enable complex "linked" data structures like linked lists and binary trees. What Is A Pointer? Simple int and float variables operate pretty intuitively. An int variable is like a box which can store a single int value such as 42. In a drawing, a simple variable is a box with its current value drawn inside.

strikeshine

c++野指针的原理以及避免方法

1.定义 指向非法的内存地址指针叫作野指针(Wild Pointer),也叫悬挂指针(Dangling Pointer),意为无法正常使用的指针。 2.出现野指针的常见情形 2.1使用未初始化的指针 出现野指针最典型的情形就是在定义指针变量之后没有对它进行初始化,如下面的程序。 #include using namespace std; int main() { int* p; cout&lt;&lt;*p&lt;&lt;endl; //编译通过,运行时出错 } 2.2指针所指的对象已经消亡 指针指向某个对象之后,当这个对象的生命周期已经结束,对象已经消亡后,仍使用指针访问该对象,将

weixin_38689922

NULL指针、零指针、野指针定义及区别

本文主要讲了NULL指针、零指针、野指针定义及区别。

weixin_38525735

野指针问题

野指针问题

myeric2008

C野指针处理

C野指针的出现,以及详细的处理办法,很好的文档哦!

思考的意义
评论 83
收藏 已收藏
分享
返回顶部
方紫涵
C++ 语言 65,214 成员 250,514 内容