User:Saugandhk/sandbox
Syntax
C has a
/*
and */
, or (since C99) following //
until the end of the line. Comments delimited by /*
and */
do not nest, and these sequences of characters are not interpreted as comment delimiters if they appear inside string or character literals.[2]C source files contain declarations and function definitions. Function definitions, in turn, contain declarations and
struct
, union
, and enum
, or assign types to and perhaps reserve storage for new variables, usually by writing the type followed by the variable name. Keywords such as char
and int
specify built-in types. Sections of code are enclosed in braces ({
and }
, sometimes called "curly brackets") to limit the scope of declarations and to act as a single statement for control structures.
As an imperative language, C uses statements to specify actions. The most common statement is an expression statement, consisting of an expression to be evaluated, followed by a semicolon; as a side effect of the evaluation, functions may be
switch
selects a case
to be executed based on the value of an integer expression.
Expressions can use a variety of built-in operators and may contain function calls. The order in which arguments to functions and operands to most operators are evaluated is unspecified. The evaluations may even be interleaved. However, all side effects (including storage to variables) will occur before the next "
Kernighan and Ritchie say in the Introduction of The C Programming Language: "C, like any other language, has its blemishes. Some of the operators have the wrong precedence; some parts of the syntax could be better."[4] The C standard did not attempt to correct many of these blemishes, because of the impact of such changes on already existing software.
Character set
The basic C source character set includes the following characters:
- Lowercase and uppercase letters:
a
–z
A
–Z
- Decimal digits:
0
–9
- Graphic characters:
! " # % & ' ( ) * + , - . / : ; < = > ? [ \ ] ^ _ { | } ~
- Whitespace characters: space, horizontal tab, vertical tab, form feed, newline
—————————————————————————————————————————— Newline indicates the end of a text line; it need not correspond to an actual single character, although for convenience C treats it as one.
Additional multibyte encoded characters may be used, but are not portable.
The latest C standard (C11) allows multinational Unicode characters to be embedded portably within C source text by using a \uDDDD
encoding (where DDDD
denotes a Unicode character code), although this feature is not yet widely implemented.
The basic C execution character set contains the same characters, along with representations for alert, backspace, and carriage return.
Keywords
C89 has 32 keywords (reserved words with special meaning):
|
|
|
C99 adds five more keywords:
|
|
|
C11 adds seven more keywords:[5]
|
|
|
|
Most of the recently added keywords begin with an underscore followed by a capital letter, because identifiers of that form were previously reserved by the C standard for use only by implementations. Since existing program source code should not have been using these identifiers, it would not be affected when C implementations started supporting these extensions to the programming language. Some standard headers do define more convenient synonyms for underscored identifiers. The language previously included a reserved keyword called entry
, but this was never implemented, and has now been removed as a reserved word.[6]
Operators
C supports a rich set of
%
- assignment:
=
- augmented assignment:
+=
,-=
,*=
,/=
,%=
,&=
,|=
,^=
,<<=
,>>=
- bitwise logic:
~
,&
,|
,^
- bitwise shifts:
<<
,>>
- boolean logic:
!
,&&
,||
? :
- equality testing:
==
,!=
- calling functions:
( )
- increment and decrement:
++
,--
- member selection:
.
,->
- object size:
sizeof
- order relations:
<
,<=
,>
,>=
- reference and dereference:
&
,*
,[ ]
- sequencing:
,
- subexpression grouping:
( )
- type conversion:
(typename)
C uses the =
operator, reserved in mathematics to express equality, to indicate assignment, following the precedent of
==
binding more tightly than &
and |
in expressions like x & 1 == 0
, which would need to be written (x & 1) == 0
to be properly evaluated.[8]- ^ Cite error: The named reference
h&s5e
was invoked but never defined (see the help page). - ISBN 7 302 02412 X.
- ^ Cite error: The named reference
k&r1e
was invoked but never defined (see the help page). - ^ Page 3 of the original K&R[3]
- ^ Cite error: The named reference
AutoTX-7
was invoked but never defined (see the help page). - ISBN 7 302 02412 X.
- ^ Cite error: The named reference
AutoTX-8
was invoked but never defined (see the help page). - ^ Cite error: The named reference
AutoTX-9
was invoked but never defined (see the help page).