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
|
---|
6 | licensed to the FSF.)
|
---|
7 |
|
---|
8 | Permission is granted to copy, distribute and/or modify this document
|
---|
9 | under the terms of the GNU Free Documentation License, Version 1.3 or
|
---|
10 | any later version published by the Free Software Foundation; with the
|
---|
11 | Invariant Sections being "GNU General Public License," with the
|
---|
12 | Front-Cover Texts being "A GNU Manual," and with the Back-Cover
|
---|
13 | Texts as in (a) below. A copy of the license is included in the
|
---|
14 | section entitled "GNU Free Documentation License."
|
---|
15 |
|
---|
16 | (a) The FSF's Back-Cover Text is: "You have the freedom to copy and
|
---|
17 | modify this GNU manual. Buying copies from the FSF supports it in
|
---|
18 | developing 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>Operators/Punctuation (GNU C Language Manual)</title>
|
---|
23 |
|
---|
24 | <meta name="description" content="Operators/Punctuation (GNU C Language Manual)">
|
---|
25 | <meta name="keywords" content="Operators/Punctuation (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="Lexical-Syntax.html" rel="up" title="Lexical Syntax">
|
---|
33 | <link href="Line-Continuation.html" rel="next" title="Line Continuation">
|
---|
34 | <link href="Identifiers.html" rel="prev" title="Identifiers">
|
---|
35 | <style type="text/css">
|
---|
36 | <!--
|
---|
37 | a.summary-letter {text-decoration: none}
|
---|
38 | blockquote.indentedblock {margin-right: 0em}
|
---|
39 | div.display {margin-left: 3.2em}
|
---|
40 | div.example {margin-left: 3.2em}
|
---|
41 | div.lisp {margin-left: 3.2em}
|
---|
42 | kbd {font-style: oblique}
|
---|
43 | pre.display {font-family: inherit}
|
---|
44 | pre.format {font-family: inherit}
|
---|
45 | pre.menu-comment {font-family: serif}
|
---|
46 | pre.menu-preformatted {font-family: serif}
|
---|
47 | span.nolinebreak {white-space: nowrap}
|
---|
48 | span.roman {font-family: initial; font-weight: normal}
|
---|
49 | span.sansserif {font-family: sans-serif; font-weight: normal}
|
---|
50 | ul.no-bullet {list-style: none}
|
---|
51 | -->
|
---|
52 | </style>
|
---|
53 |
|
---|
54 |
|
---|
55 | </head>
|
---|
56 |
|
---|
57 | <body lang="en">
|
---|
58 | <span id="Operators_002fPunctuation"></span><div class="header">
|
---|
59 | <p>
|
---|
60 | Next: <a href="Line-Continuation.html" accesskey="n" rel="next">Line Continuation</a>, Previous: <a href="Identifiers.html" accesskey="p" rel="prev">Identifiers</a>, Up: <a href="Lexical-Syntax.html" accesskey="u" rel="up">Lexical Syntax</a> [<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="Operators-and-Punctuation"></span><h3 class="section">5.6 Operators and Punctuation</h3>
|
---|
64 | <span id="index-operators"></span>
|
---|
65 | <span id="index-punctuation"></span>
|
---|
66 |
|
---|
67 | <p>Here we describe the lexical syntax of operators and punctuation in C.
|
---|
68 | The specific operators of C and their meanings are presented in
|
---|
69 | subsequent chapters.
|
---|
70 | </p>
|
---|
71 | <p>Most operators in C consist of one or two characters that can’t be
|
---|
72 | used in identifiers. The characters used for operators in C are
|
---|
73 | ‘<samp>!~^&|*/%+-=<>,.?:</samp>’.
|
---|
74 | </p>
|
---|
75 | <p>Some operators are a single character. For instance, ‘<samp>-</samp>’ is the
|
---|
76 | operator for negation (with one operand) and the operator for
|
---|
77 | subtraction (with two operands).
|
---|
78 | </p>
|
---|
79 | <p>Some operators are two characters. For example, ‘<samp>++</samp>’ is the
|
---|
80 | increment operator. Recognition of multicharacter operators works by
|
---|
81 | grouping together as many consecutive characters as can constitute one
|
---|
82 | operator.
|
---|
83 | </p>
|
---|
84 | <p>For instance, the character sequence ‘<samp>++</samp>’ is always interpreted
|
---|
85 | as the increment operator; therefore, if we want to write two
|
---|
86 | consecutive instances of the operator ‘<samp>+</samp>’, we must separate them
|
---|
87 | with a space so that they do not combine as one token. Applying the
|
---|
88 | same rule, <code>a+++++b</code> is always tokenized as <code>a++ ++ + b<!-- /@w --></code>, not as <code>a++ + ++b<!-- /@w --></code>, even though the latter could be part
|
---|
89 | of a valid C program and the former could not (since <code>a++</code>
|
---|
90 | is not an lvalue and thus can’t be the operand of <code>++</code>).
|
---|
91 | </p>
|
---|
92 | <p>A few C operators are keywords rather than special characters. They
|
---|
93 | include <code>sizeof</code> (see <a href="Type-Size.html">Type Size</a>) and <code>_Alignof</code>
|
---|
94 | (see <a href="Type-Alignment.html">Type Alignment</a>).
|
---|
95 | </p>
|
---|
96 | <p>The characters ‘<samp>;{}[]()</samp>’ are used for punctuation and grouping.
|
---|
97 | Semicolon (‘<samp>;</samp>’) ends a statement. Braces (‘<samp>{</samp>’ and
|
---|
98 | ‘<samp>}</samp>’) begin and end a block at the statement level
|
---|
99 | (see <a href="Blocks.html">Blocks</a>), and surround the initializer (see <a href="Initializers.html">Initializers</a>)
|
---|
100 | for a variable with multiple elements or components (such as arrays or
|
---|
101 | structures).
|
---|
102 | </p>
|
---|
103 | <p>Square brackets (‘<samp>[</samp>’ and ‘<samp>]</samp>’) do array indexing, as in
|
---|
104 | <code>array[5]</code>.
|
---|
105 | </p>
|
---|
106 | <p>Parentheses are used in expressions for explicit nesting of
|
---|
107 | expressions (see <a href="Basic-Arithmetic.html">Basic Arithmetic</a>), around the parameter
|
---|
108 | declarations in a function declaration or definition, and around the
|
---|
109 | arguments in a function call, as in <code>printf ("Foo %d\n", i)</code>
|
---|
110 | (see <a href="Function-Calls.html">Function Calls</a>). Several kinds of statements also use
|
---|
111 | parentheses as part of their syntax—for instance, <code>if</code>
|
---|
112 | statements, <code>for</code> statements, <code>while</code> statements, and
|
---|
113 | <code>switch</code> statements. See <a href="if-Statement.html">if Statement</a>, and following
|
---|
114 | sections.
|
---|
115 | </p>
|
---|
116 | <p>Parentheses are also required around the operand of the operator
|
---|
117 | keywords <code>sizeof</code> and <code>_Alignof</code> when the operand is a data
|
---|
118 | type rather than a value. See <a href="Type-Size.html">Type Size</a>.
|
---|
119 | </p>
|
---|
120 | <hr>
|
---|
121 | <div class="header">
|
---|
122 | <p>
|
---|
123 | Next: <a href="Line-Continuation.html" accesskey="n" rel="next">Line Continuation</a>, Previous: <a href="Identifiers.html" accesskey="p" rel="prev">Identifiers</a>, Up: <a href="Lexical-Syntax.html" accesskey="u" rel="up">Lexical Syntax</a> [<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>
|
---|
124 | </div>
|
---|
125 |
|
---|
126 |
|
---|
127 |
|
---|
128 | </body>
|
---|
129 | </html>
|
---|