Lecture Handout - 3
Lecture Handout - 3
Function defnition, Global declaration and preprocessing directivies are source code of C
prog.
Small Prog: Source code written – Single Source file
Large prog: Source code written – Several source codes
1. Preprocessor directives
2. Global declarations
3. Function definitions
int main() {
return 0;
OUTPUT:
COMMENTS IN C
IDENTIFIERS
The term identifier refers to the names of variables, functions, macros, structures
and other objects defined in a C program. Identifiers can contain the following characters:
• The letters in the basic character set, a–z and A–Z. Identifiers are case-sensitive.
• The decimal digits 0–9, although the first character of an identifier must not be a digit.
• Universal character names that represent the letters and digits of other languages.
Keywords
Keywords are special words in C programming which have their own predefined meaning. The
functions and meanings of these words cannot be altered. Some keywords in C Programming are:
The following 37 keywords are reserved in C, each having a specific meaning to the compiler, and must
not be used as identifiers:
for float go if
int long register return
int age;
float height;
Here, int is a keyword which declares age as a variable of integer data type.
Similarly, float is also a keyword which declares height is a variable of floating integer data type.
All identifiers fall into exactly one of the following four categories, which
• Label names.
• Names of structure or union members. Each structure or union constitutes a separate name space for
its members.
IDENTIFIER SCOPE:
The scope of an identifier refers to that part of the translation unit in which the
identifier is meaningful.
2.Block Scope
4. Function scope
HOW THE C COMPILER WORKS:
The compilation is a process of converting the source code into object code. It is done with the help of
the compiler.
Figure: illustrates,
1. The source file input is mapped to the source character set (if necessary). Trigraphs are replaced
in this step.
a) 5 whitespace characters (space, horizontal tab, vertical tab, form feed, new-line)
b) 10 digit characters from '0' to '9'
c) 52 letters from 'a' to 'z' and from 'A' to 'Z'
d) 29 punctuation characters: _ { } [ ] # ( ) < > % : ; . ? * + - / ^ & | ~ ! = , \ " '
2. Continuation lines (lines that end with \ ) are spliced with the next line.
3. The source code is parsed into whitespace and preprocessing tokens.
4. The preprocessor is applied, which executes directives, expands macros, and applies pragmas.
Each source file pulled in by #include undergoes translation phases 1 through 4 (recursively if
necessary). All preprocessor related directives are then deleted.
5. Source character set values in character constants and string literals are mapped to the execution
character set.
6. String literals adjacent to each other are concatenated.
7. The source code is parsed into tokens, which comprise the translation unit.
8. External references are resolved, and the program image is formed.
TOKENS:
A token is either a keyword, an identifier, a constant, a string literal, or a symbol. Symbols in C consist
of one or more punctuation characters, and function as operators or digraphs, or have syntactic
importance, like the semicolon that terminates a simple statement, or the braces { } that enclose a block
statement.
printf("Hello, world.\n");
printf
"Hello, world.\n"