c++,输出的a,b,n的值无法理解

1.输入下列程序,运行它,分析得到的结果。
#include
using namespace std;
int n = 0;
int func(int x);
void main()
{
int a,b;
a = 5;
b = func(a);
cout << "\nlocal a=" << a<< endl;
cout << "local b=" << b<
cout << "global n=" << n<
a++;
b = func(a);
cout << "\nlocal a=" << a<< endl;
cout << "local b=" << b<
cout << "global n=" << n<
}
int func(int x)
{
int a=1;
static int b=10;
a++;
b++;
x++;
n++;
cout << "\nlocal a=" << a<< endl;
cout << "local b=" << b<
cout << "global n=" << n<
return a+b;
}
[实验要求]:
运行该程序,得到运行结果
分析得到的结果,说明为什么得到这样的结果(复习自动变量、静态变量、全局变量的区别)。

main函数中的ab与func中的ab不是同一变量。两变量的作用域在各自函数内。
func中的b为静态变量,其生存期是直到程序运行结束,所以第二次执行func时,b的值不会被初期化成10,而是还会保存上次的结果。
n为全局变量,作用域是全局,生存周期是直到程序运行结束。

#include <iostream>
using namespace std;
int n = 0;
int func(int x);
void main()
{
    int a,b;
    a = 5;
    b = func(a);
    cout << "\nlocal a=" << a<< endl;//</span><br /><span style="display:inline-block;text-indent:2em;"> 
    cout << "local b=" << b<<endl;//</span><br /><span style="display:inline-block;text-indent:2em;"> 
    cout << "global n=" << n<<endl;//</span><br /><span style="display:inline-block;text-indent:2em;"> 
    a++;
    b = func(a);
    cout << "\nlocal a=" << a<< endl;//</span><br /><span style="display:inline-block;text-indent:2em;"> 
    cout << "local b=" << b<<endl;//</span><br /><span style="display:inline-block;text-indent:2em;"> 
    cout << "global n=" << n<<endl;//</span><br />
}//<br />
int func(int x)//<br />
{//<br /><span style="display:inline-block;text-indent:2em;"> 
    int a=1;
    static int b=10;
    a++;
    b++;
    x++;
    n++;
    cout << "\nlocal a=" << a<< endl;//</span><br /><span style="display:inline-block;text-indent:2em;"> 
    cout << "local b=" << b<<endl;//</span><br /><span style="display:inline-block;text-indent:2em;"> 
    cout << "global n=" << n<<endl;//</span><br /><span style="display:inline-block;text-indent:2em;">
    return a+b;
}

main函数中line9第一次调用func(a),将a值为5传给func中的x,使得x的值为5。
func中++操作前,局部变量a为1,静态变量b为10,全局变量n为0。
经过++操作,func中的局部变量a为2,静态变量b为11,全局变量n为1,返回值a+b为13,所以main函数中的b值为13。
所以line10到12输出a为5,b为13,n为1。
a++后,a的值为6,第二次调用func(a),将a的值6传给func中的x,使x的值为6。
func中++操作前,局部变量a为1,静态变量b为11,全局变量n为1。
经过++操作,func中的局部变量a为2,静态变量b为12,全局变量n为2,返回值a+b为14,所以main函数中的b值为14。
所以line15到17输出a为6,b为14,n为2。