该如何修正呢?

来源:百度知道 编辑:UC知道 时间:2024/05/16 09:58:22
1、下面程序错在哪里,为什么得不到结果10。
#include <iostream.h>

int func(void)//函数的返回值用于统计该函数调用次数//

{

static int count;

return ++count;

}

void main()

{

int i;

int count=0;

for(i=0;i<10;i++)

{

func() ;

}

cout<<"count="<<count<<endl;

}
该如何修正呢?

#include <iostream.h>

int count=0;

int func(void)//函数的返回值用于统计该函数调用次数//

{

return ++count;

}

void main()

{

int i;

for(i=0;i<10;i++)

{

func() ;

}

cout<<"count="<<count<<endl;

}