Curly bracket programming language: Difference between revisions

Content deleted Content added
Typographical concerns: add a comments section
Comments: new section
Line 120:
== Comments ==
By convention, most programming languages in this class use <code>/*</code> and <code>*/</code> as delimiters in block comments. and <code>//</code> to indicate single-line comments. Versions of C prior to C99 did not support <code>//</code> comments, but this feature was provided as an extension by most compilers.
 
== Variable declaration ==
Many C-style programming languages use [[static typing]] and require all variables to have an explicit type, even though the guarantees provided by the type systems are quite variable. Typing is generally [[nominative typing|nominative]], not structiral.
 
Basic types are usually denoted by simple lowercase words, such as <code>int</code> or <code>char</code>, optionally decorated with modifiers such as <code>unsigned</code>. In addition, declarations may also be marked by various type and storage modifiers: for instance, a constant variable may be indicated by the modifier <code>const</code>.
 
Variables are declared with a syntax which is similar to their use. In a basic declaration, the type is given first, followed by the name of the variable and an optional initial value. Multiple variables may be separated by a comma:
 
<source lang="c">
unsigned char red, blue;
int green = 0;
</source>
 
More complex types, such as pointers and arrays, are declared by means of other modifiers. <code>*</code> and <code>[]</code> are the modifiers for pointers and arrays in many C-style programming languages. A confusing feature of C syntax is that these modifiers are affixed to the variable being declared rather than the basic type, reflecting the use of <code>*</code> and <code>[]</code>. as dereferencing operators:
 
<source lang="c">
char *foo; //foo is a pointer to chars
int bar[10]; //bar is an array of ints
char **baz; //baz is a pointer to a char-pointer
</source>
 
However, various C-like languages, including [[Java]] and C#, may separate their declarations into a type followed by a list of variable names:
 
<source lang="c">
int[10] bar; // not valid C: bar is an array of ints
</source>
 
=== User-defined types ===
Type synonyms may be declared by using a syntax such as <code>typedef ''type'' ''synonym''</code> or <code>using ''synonym'' = ''type''</code>.
 
Simple composite types are declared by such syntaxes as <code>struct { ''type'' ''name''; ''type'' ''name''; ... };</code>, where ''struct'' denotes a [[record type]]. Some languages also support [[union type]]s, denoted by the <code>union</code> keyword.
 
== Typographical concerns ==