摘要:
C++中变量生存期与VB中大不相同,C++中非静态局部变量的生存周期仅限于其声明所在的块(即程序中对应的大括弧)中,在退出块时便会释放掉内存。例:class destruct{public: int mem; destruct() { mem = 0; } ~destruct() { mem++; }};void main(){ int * pa = NULL; { destruct odestruct; } if (true) { int a = 10; pa = &a; } for (int i = 0; i < 10; i++) { i++; } (*pa)++; cout 阅读全文
摘要:
#include "stdafx.h"#include <iostream>using namespace std;int globalJ =999;//返回值int test1(){ int j =1; cout<<"in test1(),[return value] the varaible j's address :"<<&j<<endl; return j;}//使用局部变量,返回引用int& test2(){int j =998;cout<<"in t 阅读全文