这个野指针不?为什么可以使用?
#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.
c++野指针的原理以及避免方法
1.定义 指向非法的内存地址指针叫作野指针(Wild Pointer),也叫悬挂指针(Dangling Pointer),意为无法正常使用的指针。 2.出现野指针的常见情形 2.1使用未初始化的指针 出现野指针最典型的情形就是在定义指针变量之后没有对它进行初始化,如下面的程序。 #include using namespace std; int main() { int* p; cout<<*p<<endl; //编译通过,运行时出错 } 2.2指针所指的对象已经消亡 指针指向某个对象之后,当这个对象的生命周期已经结束,对象已经消亡后,仍使用指针访问该对象,将
NULL指针、零指针、野指针定义及区别
本文主要讲了NULL指针、零指针、野指针定义及区别。
野指针问题
野指针问题
C野指针处理
C野指针的出现,以及详细的处理办法,很好的文档哦!


