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