source: public/doc/gnu-c/Variables.html@ 02598c2

Last change on this file since 02598c2 was 02598c2, checked in by Mikhail Kirillov <w96k@…>, on Oct 6, 2022 at 12:36:29 PM

Add gnu-c

  • Property mode set to 100644
File size: 6.9 KB
Line 
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<html>
3<!-- Copyright (C) 2022 Richard Stallman and Free Software Foundation, Inc.
4
5(The work of Trevis Rothwell and Nelson Beebe has been assigned or
6licensed to the FSF.)
7
8Permission is granted to copy, distribute and/or modify this document
9under the terms of the GNU Free Documentation License, Version 1.3 or
10any later version published by the Free Software Foundation; with the
11Invariant Sections being "GNU General Public License," with the
12Front-Cover Texts being "A GNU Manual," and with the Back-Cover
13Texts as in (a) below. A copy of the license is included in the
14section entitled "GNU Free Documentation License."
15
16(a) The FSF's Back-Cover Text is: "You have the freedom to copy and
17modify this GNU manual. Buying copies from the FSF supports it in
18developing GNU and promoting software freedom." -->
19<!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
20<head>
21<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
22<title>Variables (GNU C Language Manual)</title>
23
24<meta name="description" content="Variables (GNU C Language Manual)">
25<meta name="keywords" content="Variables (GNU C Language Manual)">
26<meta name="resource-type" content="document">
27<meta name="distribution" content="global">
28<meta name="Generator" content="makeinfo">
29<link href="index.html" rel="start" title="Top">
30<link href="Symbol-Index.html" rel="index" title="Symbol Index">
31<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
32<link href="index.html" rel="up" title="Top">
33<link href="Variable-Declarations.html" rel="next" title="Variable Declarations">
34<link href="Statement-Exprs.html" rel="prev" title="Statement Exprs">
35<style type="text/css">
36<!--
37a.summary-letter {text-decoration: none}
38blockquote.indentedblock {margin-right: 0em}
39div.display {margin-left: 3.2em}
40div.example {margin-left: 3.2em}
41div.lisp {margin-left: 3.2em}
42kbd {font-style: oblique}
43pre.display {font-family: inherit}
44pre.format {font-family: inherit}
45pre.menu-comment {font-family: serif}
46pre.menu-preformatted {font-family: serif}
47span.nolinebreak {white-space: nowrap}
48span.roman {font-family: initial; font-weight: normal}
49span.sansserif {font-family: sans-serif; font-weight: normal}
50ul.no-bullet {list-style: none}
51-->
52</style>
53
54
55</head>
56
57<body lang="en">
58<span id="Variables"></span><div class="header">
59<p>
60Next: <a href="Type-Qualifiers.html" accesskey="n" rel="next">Type Qualifiers</a>, Previous: <a href="Statements.html" accesskey="p" rel="prev">Statements</a>, Up: <a href="index.html" accesskey="u" rel="up">Top</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Index.html" title="Index" rel="index">Index</a>]</p>
61</div>
62<hr>
63<span id="Variables-1"></span><h2 class="chapter">20 Variables</h2>
64<span id="index-variables"></span>
65
66<p>Every variable used in a C program needs to be made known by a
67<em>declaration</em>. It can be used only after it has been declared.
68It is an error to declare a variable name more than once in the same
69scope; an exception is that <code>extern</code> declarations and tentative
70definitions can coexist with another declaration of the same
71variable.
72</p>
73<p>Variables can be declared anywhere within a block or file. (Older
74versions of C required that all variable declarations within a block
75occur before any statements.)
76</p>
77<p>Variables declared within a function or block are <em>local</em> to
78it. This means that the variable name is visible only until the end
79of that function or block, and the memory space is allocated only
80while control is within it.
81</p>
82<p>Variables declared at the top level in a file are called <em>file-scope</em>.
83They are assigned fixed, distinct memory locations, so they retain
84their values for the whole execution of the program.
85</p>
86<table class="menu" border="0" cellspacing="0">
87<tr><td align="left" valign="top">&bull; <a href="Variable-Declarations.html" accesskey="1">Variable Declarations</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Name a variable and and reserve space for it.
88</td></tr>
89<tr><td align="left" valign="top">&bull; <a href="Initializers.html" accesskey="2">Initializers</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Assigning inital values to variables.
90</td></tr>
91<tr><td align="left" valign="top">&bull; <a href="Designated-Inits.html" accesskey="3">Designated Inits</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Assigning initial values to array elements
92 at particular array indices.
93</td></tr>
94<tr><td align="left" valign="top">&bull; <a href="Auto-Type.html" accesskey="4">Auto Type</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Obtaining the type of a variable.
95</td></tr>
96<tr><td align="left" valign="top">&bull; <a href="Local-Variables.html" accesskey="5">Local Variables</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Variables declared in function definitions.
97</td></tr>
98<tr><td align="left" valign="top">&bull; <a href="File_002dScope-Variables.html" accesskey="6">File-Scope Variables</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Variables declared outside of
99 function definitions.
100</td></tr>
101<tr><td align="left" valign="top">&bull; <a href="Static-Local-Variables.html" accesskey="7">Static Local Variables</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Variables declared within functions,
102 but with permanent storage allocation.
103</td></tr>
104<tr><td align="left" valign="top">&bull; <a href="Extern-Declarations.html" accesskey="8">Extern Declarations</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Declaring a variable
105 which is allocated somewhere else.
106</td></tr>
107<tr><td align="left" valign="top">&bull; <a href="Allocating-File_002dScope.html" accesskey="9">Allocating File-Scope</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">When is space allocated
108 for file-scope variables?
109</td></tr>
110<tr><td align="left" valign="top">&bull; <a href="auto-and-register.html">auto and register</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Historically used storage directions.
111</td></tr>
112<tr><td align="left" valign="top">&bull; <a href="Omitting-Types.html">Omitting Types</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">The bad practice of declaring variables
113 with implicit type.
114</td></tr>
115</table>
116
117<hr>
118<div class="header">
119<p>
120Next: <a href="Type-Qualifiers.html" accesskey="n" rel="next">Type Qualifiers</a>, Previous: <a href="Statements.html" accesskey="p" rel="prev">Statements</a>, Up: <a href="index.html" accesskey="u" rel="up">Top</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Index.html" title="Index" rel="index">Index</a>]</p>
121</div>
122
123
124
125</body>
126</html>
Note: See TracBrowser for help on using the repository browser.