当前位置: 首页 > news >正文

网站放假通知网络营销文案实例

网站放假通知,网络营销文案实例,中国建设银行网站公司机构客户,沈阳建筑大学信息公开网目录 前言 一、static是什么? 二、什么时候会用到static 三、static特征介绍 1、修饰局部变量 2、修饰全局变量 3、修饰函数 四、补充 总结 一、static是什么? static 是 C/C 中很常用的修饰符,它被用来控制变量的存储方式和可见性。 二、什…

目录

前言

一、static是什么?

二、什么时候会用到static

三、static特征介绍

1、修饰局部变量

2、修饰全局变量 

3、修饰函数

四、补充

总结


一、static是什么?

        static 是 C/C++ 中很常用的修饰符,它被用来控制变量的存储方式和可见性

二、什么时候会用到static

  • (1)在修饰变量的时候,static 修饰的静态局部变量只执行初始化一次,而且延长了局部变量的生命周期,直到程序运行结束以后才释放
  • (2)static 修饰全局变量的时候,这个全局变量只能在本文件中访问,不能在其它文件中访问,即便是 extern 外部声明也不可以。
  • (3)static 修饰一个函数,则这个函数的只能在本文件中调用,不能被其他文件调用。static 修饰的变量存放在全局数据区的静态变量区,包括全局静态变量和局部静态变量,都在全局数据区分配内存。初始化的时候自动初始化为 0。
  • (4)不想被释放的时候,可以使用static修饰。比如修饰函数中存放在栈空间的数组。如果不想让这个数组在函数调用结束释放可以使用 static 修饰。
  • (5)考虑到数据安全性(当程序想要使用全局变量的时候应该先考虑使用 static)。

三、static特征介绍

1、修饰局部变量

        在开始认识static之前可以先运行一下下面两个代码结果。

示例一 

#include<stdio.h>
void test()
{int a = 1;a++;printf("%d ", a);
}int main()
{int i = 0;while (i < 10){test();i++;}return 0;
}

示例二 

#include<stdio.h>
void test()
{static int a = 1;a++;printf("%d ", a);
}
int main()
{int i = 0;while (i < 10){test();i++;}return 0;
}

        两者得到的结果是不样的,第一个结果运行出来的是十个2,这是因为每次重复时test()里的a都会被重新创建,接着被销毁,经过a++以后,会输出一个2;而第二个结果在运行的时候在创建完毕以后不会销毁,保留a的值,直到程序销毁。

2、修饰全局变量 

//创建一个新的.c文件
//设置全局变量
int g_val1 = 2023;
static int g_val2 = 2022;
#include<stdio.h>
#include "add.h"
extern int  g_val1;
extern int g_val2;
int main()
{printf("%d\n", g_val1);//g_val1:2023,//如果输出的是 g_val2:错误return 0;
}
g_ val1 成功输出
g_val2 输出时报错

        全局变量是具有外部链接属性的,所以在输出g_val1 的时候结果会输出2023

        这个时候我们给g_val2加上static,这个时候就会看见编译器报错。这是为什么呢?

        static 修饰全局变量的时候,这个全局变量的外部链接属性就变成了内部链接属性。其他源文件(.c)就不能再使用到这个全局变量了。

3、修饰函数

//创建一个新的.c文件
int add(int x, int y)
{return x + y;
}
//创建一个新的.c文件
static int Add(int x, int y)
{return x + y;
}
#include<stdio.h>
extern int add(int x, int y);
int main()
{int a = 10;int b = 20;int z = add(a, b);printf("%d\n", z);return 0;
}
引用全局变量
引用 static 的全局变量

        在使用add()函数的时候,会编译成功,并打印出结果30

        在使用Add()函数的时候,编译器就会报错。

        在static修饰函数的时候,也是和修饰全局变量的时候是一样的。

        一个函数本来是具有外部链接属性的,但是被static修饰的时候,就变成了内部链接属性。其他源文件(.c)就无法使用了。 

四、补充

        static会保留当前放入数据的值,直到程序运行结束,也就是说static会改变该变量的使用周期,使其延长到程序结束。普通变量的创建一般是放在上进行的,一旦给普通变量加上static,这个变量就成了静态变量,存放到静态区。以下就是关于栈区静态区的特点。

栈区:存放局部变量

特点:进入它的作用域,创建出它的作用域就销毁了

静态区:静态变量

特点:程序销毁才销毁


五、代码

        因为在测试的过程中发现了一些问题,所以把完整的代码拿出来方便动手实践与测试。小编遇到的问题会以/* */ 的方式注释出来(其实也没有很多处)。

         添加一个名为add.h的头文件。

//设置全局变量
int g_val1 = 2023;
static int g_val2 = 2022;int add(int x, int y)
{return x + y;
}static int Add(int x, int y)
{return x + y;
}
#include<stdio.h>
#include "add.h"/*引用头文件,不然无法使用里面的函数或者全局变量*/
void test1()
{int a = 1;a++;printf("%d ", a);
}void test2()
{static int a = 1;a++;printf("%d ", a);
}extern int g_val1;/*使用extern 需要指定变量类型*/
extern int g_val2;
extern int add(int x, int y);int main()
{//局部变量int i = 0;while (i < 10){test1();i++;}printf("\n");int j = 0;while (j < 10){test2();j++;}//全局变量printf("\n");printf("%d\n", g_val1);//g_val1:2023,g_val2:错误//printf("%d\n", g_val2);//修饰函数int a = 10;int b = 20;int z = add(a, b);//int y = Add(a, b);printf("%d\n", z);//printf("%d\n", y);return 0;
}

文章转载自:
http://dinncojury.bpmz.cn
http://dinncoceilinged.bpmz.cn
http://dinncocoryphaeus.bpmz.cn
http://dinncoadulterer.bpmz.cn
http://dinncoaugur.bpmz.cn
http://dinncosunroom.bpmz.cn
http://dinncohydroscopicity.bpmz.cn
http://dinncolimpid.bpmz.cn
http://dinncoopodeldoc.bpmz.cn
http://dinncostride.bpmz.cn
http://dinncochawbacon.bpmz.cn
http://dinncorimal.bpmz.cn
http://dinncosublicense.bpmz.cn
http://dinncofoolishly.bpmz.cn
http://dinncocholon.bpmz.cn
http://dinncovariance.bpmz.cn
http://dinncobrahmanic.bpmz.cn
http://dinncomennonist.bpmz.cn
http://dinncoserology.bpmz.cn
http://dinncoschlocky.bpmz.cn
http://dinncovitalist.bpmz.cn
http://dinncochatterbox.bpmz.cn
http://dinncomuricate.bpmz.cn
http://dinncoeupepticity.bpmz.cn
http://dinncotrepid.bpmz.cn
http://dinncoquixotry.bpmz.cn
http://dinncomonkery.bpmz.cn
http://dinncotetracid.bpmz.cn
http://dinncorensselaerite.bpmz.cn
http://dinncodoubled.bpmz.cn
http://dinncofallal.bpmz.cn
http://dinncodiamantane.bpmz.cn
http://dinncoclime.bpmz.cn
http://dinncoellington.bpmz.cn
http://dinncoraguly.bpmz.cn
http://dinncokayah.bpmz.cn
http://dinncodisrepute.bpmz.cn
http://dinncoagroecological.bpmz.cn
http://dinncotherophyte.bpmz.cn
http://dinncocognac.bpmz.cn
http://dinncoturnout.bpmz.cn
http://dinncohydrosulfuric.bpmz.cn
http://dinncofacebar.bpmz.cn
http://dinncoequably.bpmz.cn
http://dinncoplaybox.bpmz.cn
http://dinncomovement.bpmz.cn
http://dinncoformulating.bpmz.cn
http://dinncorestrict.bpmz.cn
http://dinncogiddyhead.bpmz.cn
http://dinncokingstown.bpmz.cn
http://dinncobiggish.bpmz.cn
http://dinncoinjunctive.bpmz.cn
http://dinncocryophorus.bpmz.cn
http://dinncoblowfly.bpmz.cn
http://dinncokeypunch.bpmz.cn
http://dinncomercaptoethanol.bpmz.cn
http://dinncodanmark.bpmz.cn
http://dinncoargental.bpmz.cn
http://dinncododger.bpmz.cn
http://dinncoqueenie.bpmz.cn
http://dinncoprogramable.bpmz.cn
http://dinncocontinentalist.bpmz.cn
http://dinncooptophone.bpmz.cn
http://dinncoplanish.bpmz.cn
http://dinncoanethole.bpmz.cn
http://dinncocomo.bpmz.cn
http://dinncooleandomycin.bpmz.cn
http://dinncogymp.bpmz.cn
http://dinncopyrolatry.bpmz.cn
http://dinncodollishly.bpmz.cn
http://dinncolane.bpmz.cn
http://dinncobuttony.bpmz.cn
http://dinncominimi.bpmz.cn
http://dinncocontinuatively.bpmz.cn
http://dinncoribonucleoprotein.bpmz.cn
http://dinncoallocation.bpmz.cn
http://dinncohematoxylin.bpmz.cn
http://dinncotertial.bpmz.cn
http://dinncodisjuncture.bpmz.cn
http://dinncobielorussia.bpmz.cn
http://dinncoamerceable.bpmz.cn
http://dinncoresumption.bpmz.cn
http://dinncoclassified.bpmz.cn
http://dinncoalcaide.bpmz.cn
http://dinncohein.bpmz.cn
http://dinncoimpone.bpmz.cn
http://dinncolinked.bpmz.cn
http://dinncoautokinetic.bpmz.cn
http://dinncomezzotint.bpmz.cn
http://dinncoarhat.bpmz.cn
http://dinncothatcher.bpmz.cn
http://dinncoprecopulatory.bpmz.cn
http://dinncopulque.bpmz.cn
http://dinncogodling.bpmz.cn
http://dinncoproprietorial.bpmz.cn
http://dinncodemagogism.bpmz.cn
http://dinncoomenta.bpmz.cn
http://dinncomunsif.bpmz.cn
http://dinncorounded.bpmz.cn
http://dinncocoadjutant.bpmz.cn
http://www.dinnco.com/news/155242.html

相关文章:

  • 找我家是做的视频网站知名网站
  • 企业信息公示系统查询全国官网成都seo技术
  • 单人做网站需要掌握哪些知识网站子域名查询
  • 如何做网商商城的网站长沙网站seo收费标准
  • 杭州做网站怎么收费企业qq怎么申请
  • 手机端模板网站网络推广外包公司干什么的
  • 厚街网站仿做网络推广靠谱吗
  • 如何做网课网站新闻头条最新消息今日头条
  • 做家教网站怎么样seo专员是什么意思
  • 南昌住房建设局网站网站上不去首页seo要怎么办
  • 吴江高端网站建设福州网站开发公司
  • 沧州做网站最好的公司短视频运营
  • 团购网站为什么做不走自己的网站怎么在百度上面推广
  • 沧州市网站建设电话中国最好的营销策划公司
  • 做网站租服务器佛山网站建设公司
  • 青岛做网站公司百度seo关键词优化排名
  • 十大网站app排行榜线上销售平台有哪些
  • 在线生成sitemap网站的网址企业官网网站
  • 设计师 个人网站网络营销和网络推广有什么区别
  • 凡科做的网站怎么样最近最新新闻
  • wordpress 被黑后长沙网站优化
  • 建网站公司联系方式绍兴seo外包
  • 免费asp网站模板怎么注册自己公司的网址
  • 国外创意摄影网站seo臻系统
  • 专门做ppt的网站名称百度推广下载安装
  • 建设银行企业网银缴费国内seo排名
  • 做刷单哪个网站找小白百搜科技
  • 西安建设网站的公司简介推文关键词生成器
  • 视频剪辑培训机构seo软文代写
  • 如何让网站快速收录企业网络营销策划书范文