分类: C/C++
2013-02-19 19:38:21
代码区(code area)
|
程序内存空间
|
全局数据区(data area)
|
|
堆区(heap area)
|
|
栈区(stack area)
|
int a = 0; //全局初始化区
char *p1; //全局未初始化区
int main() {
int b; //栈
char s[] = /"abc/"; //栈
char *p2; //栈
char *p3 = /"123456/"; //123456//0在常量区,p3在栈上。
static int c =0;//全局(静态)初始化区
p1 = new char[10];
p2 = new char[20];
//分配得来得和字节的区域就在堆区。
strcpy(p1, /"123456/"); //123456//0放在常量区,编译器可能会将它与p3所指向的/"123456/"优化成一个地方。
}
|
int main(){
char a = 1;
char c[] = /"1234567890/";
char *p =/"1234567890/";
a = c[1];
a = p[1];
return 0;
}
|
10: a = c[1];
00401067 8A 4D F1 mov cl,byte ptr [ebp-0Fh] 0040106A 88 4D FC mov byte ptr [ebp-4],cl 11: a = p[1]; 0040106D 8B 55 EC mov edx,dword ptr [ebp-14h] 00401070 8A 42 01 mov al,byte ptr [edx+1] 00401073 88 45 FC mov byte ptr [ebp-4],al |
class Time{
public:
Time(int,int,int,string);
~Time(){
cout<"call Time/'s destructor by:/"<
}
private:
int hour;
int min;
int sec;
string name;
};
Time::Time(int h,int m,int s,string n){
hour=h;
min=m;
sec=s;
name=n;
cout<"call Time/'s constructor by:/"<
}
int main(){
Time *t1;
t1=(Time*)malloc(sizeof(Time));
free(t1);
Time *t2;
t2=new Time(0,0,0,/"t2/");
delete t2;
system(/"PAUSE/");
return EXIT_SUCCESS;
}
|