野指针被赋值,危险吗?
《C++设计模式_基于QT4开源跨平台开发框架》书上P429的一段代码:
//编译器是Dev-C++...int main(){ int myint = 5; int *ptr1 = &myint; cout<<"*ptr1 = "<<*ptr1<<endl; int anotherint = 6; int *ptr2; cout<<"*ptr2 = "<<*ptr2<<endl; *ptr2 = anotherint; //+ int yetanotherint = 7; int *ptr3; ptr3 = &yetanotherint; cout<<"*ptr3 = "<<*ptr3<<endl; *ptr1 = *ptr2; //危险的赋值 cout<<"*ptr1 = "<<*ptr1<<endl;}