组建-开始调试-step into-多个F10。
通过对下面这个例子的调试明白了如下问题:
1,静态变量赋值前默认值为0.
2,普通int变量复制前默认值为-8……很小的一个数。
3,子函数内有同名变量时,隐藏外层同名变量。
4,有些事怎么看也不懂,耐心调试了一遍就懂了。
----------------------------------------------------------------
#include<iostream.h>
int i=1;
int main()
{ static int a;
int b=-10;
int c=0;
void other(void);
cout<<"------main-------"<<endl;
cout<<"i="<<i<<"a="<<a<<"b="<<b<<"c="<<c<<endl;
c=c+8;
other();
cout<<"------main-------"<<endl;
cout<<"i="<<i<<"a="<<a<<"b="<<b<<"c="<<c<<endl;
other();
//system("pause");
}
void other(void)
{
static int a=1;
static int b;
int c=5;
i=i+2;a=a+3;c=c+5;
cout<<"------other-------"<<endl;
cout<<"i="<<i<<"a="<<a<<"b="<<b<<"c="<<c<<endl;
b=a;
}
输出
------main-------
i=1a=0b=-10c=0
------other-------
i=3a=4b=0c=10
------main-------
i=3a=0b=-10c=8
------other-------
i=5a=7b=4c=10