当前位置:首页 > Software > C++ > 正文内容

变量作用域

chanra1n5年前 (2020-10-28)C++6128
#include<iostream>
void print();
int main()
{
	char a=0;
	for(a=0;a<20;a++)
	print();
	return 0;
 } 
void print()
{
	static int x=0;//静态变量声明,其值会一直保留 
	x++;
	std::cout<<x<<std::endl; 
}


扫描二维码推送至手机访问。

版权声明:本文由我的FPGA发布,如需转载请注明出处。

本文链接:https://www.myfpga.cn/index.php/post/157.html

分享给朋友:

“变量作用域” 的相关文章

C++入门 输出Hello World

C++入门 输出Hello World

#include <iostream>using namespace std;int main(){     cout << "Hello, world!...

数据类型及其占用空间

数据类型及其占用空间

#include<iostream> using namespace std; int main() { cout << "The size of int is&nb...

函数声明和使用

函数声明和使用

#include<iostream> using namespace std; int sum(int a,int b);//函数声明  int main() { cout <<&nb...

Break和Continue的区别

Break和Continue的区别

#include<iostream>  using namespace std; int main() { int x=0; for(x=0;x<10;x++) { if(x==3) break;...

C和C++中的字符串

C和C++中的字符串

/*C风格字符串的声明和使用  #include<cstdio.h> int main() { char x[]={'H','e','l','l','o','&...

C++ 数组的各类性质和用法

C++ 数组的各类性质和用法

#include<iostream>  using namespace std; void addarr(int *k,int len); //文中形如sizeof(x)/sizeof(x[0]) 是用数组占用空...