From faff9260a04b024e4e6848c45954a382abbb80c3 Mon Sep 17 00:00:00 2001 From: taynpg <taynpg@163.com> Date: Sun, 2 Jun 2024 21:21:01 +0800 Subject: [PATCH] =?UTF-8?q?cpp=E5=85=A8=E5=B1=80static=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E4=B8=8E=E9=9D=9Estatic=E5=8C=BA=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cppbase/question/cpp.txt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 cppbase/question/cpp.txt diff --git a/cppbase/question/cpp.txt b/cppbase/question/cpp.txt new file mode 100644 index 0000000..83b72bc --- /dev/null +++ b/cppbase/question/cpp.txt @@ -0,0 +1,5 @@ +1.在一个cpp文件的全局区,写一个int a = 0与static int a = 0的区别是什么? +答:主要在于变量的链接性(linkage)和可见性(visibility)。 +(1)int a = 0, 整个程序的所有源文件中可见(只要在其他文件中使用extern声明它)。 +(2)static修饰的全局变量具有内部链接性,意味着这个变量仅在定义它的源文件中可见,不能被其他源文件访问和使用。 +也不能使用 extern 去访问。 \ No newline at end of file