Professional Documents
Culture Documents
FUNDAMENTALS
Program
2. If the remainder of the division is zero, the number is even; otherwise, the
number is odd.
Computer Language
1. Machine language
2. Assembly language
3. Higher-Level language
INTRODUCTION TO ‘C’
‘C’ has very small instruction set. But the actual implementation varies from
compiler to compiler and includes extensive library functions, which enhance the
basic instructions. For example, all the input and output commands are
implemented as functions but not kept as part of the language constructs.
‘C’ is highly portable i.e., software written for one computer can be run an
another computer. ‘C’ language is well suited for structured programming.
A ‘C’ program is basically a collection of functions. It encourages us to write our
own functions and add to the ‘C’ library. Also ‘C’ is modular i.e. a unit of task can be
performed by a single function. The large number of functions makes programming
task simple.
Special Symbols :
~ Tilde
‘ Apostrophe/Single quote
! Exclamatory
@ At the rate
# Hash
% Percentage
^ Caret
& Ampersand
* Asterisk
( Open parenthesis
) Closing parenthesis
_ Underscore
- Hyphen
+ Plus sign
= Equal sign
\ Back slash
/ Forward slash
{ Open brace
} Closing brace
[ Open bracket
] Closing bracket
: Colon
; Semi colon
“ Double quotes
? Question mark
< Less than symbol
> Greater than symbol
| Pipe symbol
$ Dollar sign
A token is an atomic unit of source program i.e. the compiler will not break
down the token further. For example main, { }, () are all tokens of ‘C’ program. The
tokens comprise the basic elements of the language.
Key words : Key words are predefined tokens in C. These are also called as
reserved words. Keywords have special meaning to the ‘C’ compiler. These
keywords can be used only for their intended action; they cannot be used for any
other purpose.
volatile while
Every ‘C’ program starts with a function called main(). This is the place where
program execution begins. The functions are building blocks of ‘C’ program. Each
function has a name and a list of parameters or arguments that the function will
receive. Arguments are variables or values sent to the function, which are used
inside the function.
main( ) is the start of the main program. The word main is followed by a pair
of ordinary parenthesis( ), which indicates that main is also a function. The left brace
‘{ ‘ represents the beginning of the function where as the right brace ‘}’ represents the
end of the function. The main contains variable declarations, program statements
and function calls.
2. ‘C’ is case-sensitive. That is, upper case and lower case characters are different.
generally the statements are typed in lower case.
3. A ‘C’ statement can be written in one line or it can split into multiple lines.
4. Braces must always match upon pairs i.e., every opening brace ‘{‘ must have a
matching closing brace ‘}’.
5. No restriction in using blank spaces or blank lines, that separate different words
or different parts of a program. But blank spaces are not allowed within a
variable, constant or keyword.
6. Comments cannot be nested.
7. A comment can be split into more than one line.
Comments :
Fig. Below shows the steps that are involved in entering, compiling and
executing a ‘C’ program.
Start
Edit
Source
Program
Prog1.c
Compile
(and assemble)
Yes
Object
Errors?
Program
No Prog1.obj
Link
Libraries Executable
Program
and other
Prog1.exe
object
programs Execute
No
Results
OK ?
Yes
Done
The program is first typed into a File like prog1.c on the computer system. ‘C’
program has the .c as extension. A text editor is used to enter the ‘C’ program. The
program that is entered into the file is known as source program.
The compilation process is initiated by giving a special command on the
system.
In the first step of the compilation process, the compiler examines each
program statement contained in the source program and checks to ensure that it
conforms to the syntax and semantics of the language. If any mistakes are discovered
by the compiler, they are reported to the user. The errors have to be corrected in the
source program, and the compilation process must be restarted. The successful
compilation process creates object code with .obj extension i.e. prog1.obj.
After the program has been translated into object code, it is ready to be linked.
This process is performed automatically, when we give execute command.
The final linked file, which is in an executable object code format, is stored in
another file with .exe extension i.e. prog1.exe and program will be executed
automatically.
If all goes well, the program performs its intended functions. If the program
does not produce the desired results, it is necessary to go back and reanalyse the
programs logic. The process of finding out logical errors in a program is called
debugging.
Language Interpreters