2. Introduction to C
C is a general purpose, procedural, structured computer
programming language developed by
Dennis Ritchie in the year 1972 at AT&T Bell Labs.
C language was developed on UNIX and was invented
to write UNIX system software.
C is a successor of B language.
• C was initially developed for writing system software
• Many other commonly used programming languages such as
C++ and Java are also based on C.
There are different C standards: K&R C std, ANSI C, ISO C.
3. Characteristics of C
High-Level Language: C allows programmers to focus on solving
problems without worrying about machine code.
Small Size: C has only 32 keywords, making it relatively easy to learn.
Function Calls: C uses function calls extensively, which helps organize
code and make it reusable.
Structured Programming: C supports structured programming,
allowing users to break down problems into smaller modules that
combine to form a complete program.
Loose Typing: Unlike some languages, C allows variables to be
treated as different types (e.g., a character can be treated as an
integer).
Stable Language: C is known for its reliability and stability in software
development.
4. Fast and Efficient: C programs use operators and data types
effectively, resulting in quick execution.
Low-Level Programming: C enables bitwise operations, allowing
for detailed control over hardware.
Portability: C programs can run on different computers with
little or no changes, making it a portable language.
5. A C program contains one or more functions
• The statements in a C program are written in a logical
sequence to perform a specific task.
• Execution of a C program begins at the main() function
• You can choose any name for the functions.
• Every program must contain one function that has its
name as main().
Where, #include refers to the preprocessor statement
used for the standard input/output functions and it
starts with the hash (#) symbol.
main( ):- Refers to the function from where the
execution of the program begins.
6. Source code file
• A source code is a list of commands that has to be assembled
or compiled into an executable computer program.
• The source code file contains the source code of the program.
The file extension of any C source code file is “.c”.
• This file contains C source code that defines the main function
and maybe other functions.
• The main() is the starting point of execution when you
successfully compile and run the program.
• A C program in general may include even other source code
files (with the file extension .c).
7. Header file
• When working with large projects, it is often desirable to
make sub-routines and store them in a different file known as
header file. The advantage of header files can be realized when
a) The programmer wants to use the same subroutines in
different programs.
b) The programmer wants to change, or add, subroutines, and
have those changes be reflected in all other programs.
• Conventionally, header files names ends with a “.h” extension
and its name can use only letters, digits, dashes, and
underscores.
• While some standard header files are available in C, but the
programmer may also create his own user defined header files
8. Standard Header file
Examples of standard header files are:
1. string.h: for string handling functions.
2. stdlib.h: for some miscellaneous functions.
3. stdio.h: for standardized input and output functions.
4. math.h: for mathematical functions
5. alloc.h: for dynamic memory allocation.
6. conio.h: for clearing the screen
9. Object Files:
• Object files are generated by the compiler as a result of
processing the source code file.
• Object files contain compact binary code of the function
definitions.
• Linker uses this object file to produce an executable file (.exe
file) by combining the of object files together.
• Object files have a “.o” extension, although some operating
systems including Windows and MS-DOS have a “.obj”
extension for the object file.
10. Binary Executable File
• The binary executable file is generated by the linker.
• The linker links the various object files to produce a binary file
that can be directly executed.
• On Windows operating system, the executable files have
“.exe” extension
11. C tokens
• Tokens are the basic building blocks in C language.
• It is the smallest individual unit in C program.
• A program is constructed using a combination of these
tokens. 6main types of tokens in C are:
4. White space characters: These characters are used to print a
blank space on the screen like b, t, v, r, f, n.
5. Escape sequences.
12. Character set in C
• In C, character means any letter from English alphabet, a digit
or a special symbol used to represent information.
• The character set of C can therefore be given as:
1. English alphabet: Include both lower case (a-z) as well upper
case (A-Z) letters.
2. Digits: Include numerical digits from 0 to 9.
3. Special characters: Include symbols such as ~, @, %, ^, &, *, {,
}, <, >, =, _, +, -, $, /, (, ), , ;, : , [, ], ‘, “, ?, ., !, |
13. Keywords
• C has a set of 32 reserved words often known as keywords.
• All keywords are basically a sequence of characters that have
a fixed meaning.
• By convention all keywords must be written in lowercase
(small) letters.
• It can be of any reasonable length.
Though it should not contain more than 31 characters.
14. Identifiers
Identifiers are names given to program elements such as
variables, arrays and functions.
Rules for forming identifier name
1. It cannot include any special characters or punctuation marks
(like #, $, ^, ?, ., etc) except the underscore"_".
2. There cannot be two successive underscores
3. Keywords cannot be used as identifiers
4. The names are case sensitive. So, example, “FIRST” is
different from “first” and “First”.
5. It must begin with an alphabet or an underscore.