什么是静态的int类型的和int一个区别? [英] What is the difference between static int a and int a?

查看:142
本文介绍了什么是静态的int类型的和int一个区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/959889/difference-between-global-and-static-global\">Difference与全球和静态全局

什么是报表1和2之间的区别: -

What is the difference between statements 1 and 2 :-

#include <stdio.h>
//In the global declaration area 

static int a; // 1.
int b;        // 2.

感谢您的帮助。

推荐答案

A 静态全局变量是本地的它被定义nofollow的>翻译单元所以,如果你定义静态int类型的。在两个不同的翻译单元,这将创建两个独立的变量。如果你定义的非静态全局变量 INT B:两个翻译单元,您将体验一个链接错误(但你可以使用的extern INT b ; 两个翻译单元,告诉它应该使用全局变量从其他翻译单元连接器)之一

A static global variable is local to the translation unit it is defined in. So, if you define static int a; in two different translation units, this will create two independent variables. If you define a non-static global variable int b; in two translation units, you will experience a linker error (but you can use extern int b; in one of the two translation units to tell the linker that it should use the global variable from the other translation unit).

这篇关于什么是静态的int类型的和int一个区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆