4c Basic Syntax
4c Basic Syntax
http://www.tuto rialspo int.co m/cpro g ramming /c_basic_syntax.htm Co pyrig ht tuto rials po int.co m
You have seen a basic structure of C prog ram, so it will be easy to understand other basic building blocks of the
C prog ramming lang uag e.
Tokens in C
A C prog ram consists of various tokens and a token is either a keyword, an identifier, a constant, a string literal,
or a symbol. For example, the following C statement consists of five tokens:
printf
(
"Hello, World! \n"
)
;
Semicolons ;
In C prog ram, the semicolon is a statement terminator. T hat is, each individual statement must be ended with a
semicolon. It indicates the end of one log ical entity.
Comments
Comments are like helping text in your C prog ram and they are ig nored by the compiler. T hey start with /* and
terminates with the characters */ as shown below:
/* my first program in C */
You cannot have comments within comments and they do not occur within a string or character literals.
Identifiers
A C identifier is a name used to identify a variable, function, or any other user-defined item. An identifier starts
with a letter A to Z or a to z or an underscore _ followed by zero or more letters, underscores, and dig its (0 to
9).
C does not allow punctuation characters such as @, $, and % within identifiers. C is a c ase sensitive
prog ramming lang uag e. T hus, Manpower and manpower are two different identifiers in C. Here are some
examples of acceptable identifiers:
Keywords
T he following list shows the reserved words in C. T hese reserved words may not be used as constant or
variable or any other identifier names.
double
Whitespace in C
A line containing only whitespace, possibly with a comment, is known as a blank line, and a C compiler totally
ig nores it.
Whitespace is the term used in C to describe blanks, tabs, newline characters and comments. Whitespace
separates one part of a statement from another and enables the compiler to identify where one element in a
statement, such as int, ends and the next element beg ins. T herefore, in the following statement:
int age;
T here must be at least one whitespace character (usually a space) between int and ag e for the compiler to be
able to disting uish them. On the other hand, in the following statement:
No whitespace characters are necessary between fruit and =, or between = and apples, althoug h you are free to
include some if you wish for readability purpose.