Qspiders Campus Connect v1.0.0
Chapter 1 - Introduction
C is a general-purpose high level language that was originally developed by Dennis Ritchie
for the UNIX operating system. It was first implemented on the Digital Equipment
Corporation PDP-11 computer in 1972.
The Unix operating system and virtually all Unix applications are written in the C language.
C has now become a widely used professional language for various reasons.
• Easy to learn
• Structured language
• It produces efficient programs.
• It can handle low-level activities.
• It can be compiled on a variety of computers.
1.1 Facts about C
• C was invented to write an operating system called UNIX.
• C is a successor of B language which was introduced around 1970
• The language was formalized in 1988 by the American National Standard Institute
(ANSI).
• By 1973 UNIX OS almost totally written in C.
• Today C is the most widely used System Programming Language.
• Most of the state of the art software have been implemented using C
1.2 Why to use C?
C was initially used for system development work, in particular the programs that make-up
the operating system. C was adoped as a system development language because it produces
code that runs nearly as fast as code written in assembly language. Some examples of the use
of C might be:
• Network Drivers
• Modern Programs
• Data Bases
• Language Interpreters
• Utilities
1.3. C Program File
All the C programs are writen into text files with extension ".c" for example hello.c. You can
use "vi" editor to write your C program into a file.
Vishal C Vanaki 1|Page
,Qspiders Campus Connect v1.0.0
1.4. C Compilers
When you write any program in C language then to run that program you need to compile
that program using a C Compiler which converts your program into a language
understandable by a computer. This is called machine language (ie. binary format). So before
proceeding, make sure you have C Compiler available at your computer. It comes alongwith
all flavors of Unix and Linux.
If you are working over Unix or Linux then you can type gcc -v or cc -v and check the result.
You can ask your system administrator or you can take help from anyone to identify an
available C Compiler at your computer.
1.5. Execution flow of C program
Source File
(.c extension)
Preprocessor
Extended
Source code
Compiler
Assembly code
(.asm file)
Assembler
Library Object Object code
code (.obj file)
Linker
Executable file
(.exe file)
Vishal C Vanaki 2|Page
,Qspiders Campus Connect v1.0.0
When we execute a C program these are steps that take place.
To execute the c program in Turbo C. press CTRL+F9.
1) The source code will be submitted to the preprocessor. Preprocessor is a software and part
of compiler which extends the source code by adding prototypes of pre-defined functions,
removing comments, replacing macros with its definition, etc.
2) The extended source code will then be submitted to the compiler, which intern generates
the assembly code (.asm).
3) This .asm file will be given as the input to the assembler which generates the object code(
machine readable- .obj file).
4) This object code and the library object codes (object codes of predefined function) will be
linked by the Linker. Then it generates executable file (.exe)
1.6. Syntax of C program
Different programming languages have their own format of coding. The basic components of
a C program are:
• Main()
• A pair of curly braces {,}
• Declarations and statements.
• User-defined functions.
The complete structure of a C program is shown below
Preprocessor_statements
Global_declarations;
main( )
{
Local_declarations;
statements;
}
User_defined_function
Preprocessor statements
These statements begin with # symbol, and are also called the preprocessor directives. These
statements direct the C preprocessor to include header files and also symbolic constants into a
C program.
Vishal C Vanaki 3|Page
, Qspiders Campus Connect v1.0.0
Some of preprocessor statements are given below
#include <stdio.h> : for the standard input/output functions
#include “Test.h” : for file inclusion of header file Test.
#define NULL 0 : for defining symbolic constant, NULL=0
Global Declarations
Variables or functions whose existence is known in the main( ) function and other user
defined functions, are called the global variables (of functions) and their declarations are
called the global declarations. This declaration should be made before main( ) as shown
above.
The main( ) function
As the name itself indicates, this is the main function of every C program. Execution of a C
program starts with main( ). No C program is executed without the main( ) function. The
function main( ) should be written in lower case letters and should not be terminated by a
semicolon. It calls other library functions and user defined functions. There must be one and
only one main( ) function in every C program.
Braces
Every C program uses a pair of curly braces ({,}). The left barce indicates the beginning of
the main() function. On the other hand, the right brace indicates the end of the main()
function. The braces can also be used to indicate the beginning and end of user-defined
functions and the compound statements.
Local declarations
The declaration is a part of the C program where all the variables, arrays, functions etc. used
in the C program are declared and may be initialized with their basic data types.
Statements
These are instructions to the computer to perform some specific operations.
User-defined functions
These are sub programs. The user-defined function contains a set of statements to perform a
specific task.
Vishal C Vanaki 4|Page
Chapter 1 - Introduction
C is a general-purpose high level language that was originally developed by Dennis Ritchie
for the UNIX operating system. It was first implemented on the Digital Equipment
Corporation PDP-11 computer in 1972.
The Unix operating system and virtually all Unix applications are written in the C language.
C has now become a widely used professional language for various reasons.
• Easy to learn
• Structured language
• It produces efficient programs.
• It can handle low-level activities.
• It can be compiled on a variety of computers.
1.1 Facts about C
• C was invented to write an operating system called UNIX.
• C is a successor of B language which was introduced around 1970
• The language was formalized in 1988 by the American National Standard Institute
(ANSI).
• By 1973 UNIX OS almost totally written in C.
• Today C is the most widely used System Programming Language.
• Most of the state of the art software have been implemented using C
1.2 Why to use C?
C was initially used for system development work, in particular the programs that make-up
the operating system. C was adoped as a system development language because it produces
code that runs nearly as fast as code written in assembly language. Some examples of the use
of C might be:
• Network Drivers
• Modern Programs
• Data Bases
• Language Interpreters
• Utilities
1.3. C Program File
All the C programs are writen into text files with extension ".c" for example hello.c. You can
use "vi" editor to write your C program into a file.
Vishal C Vanaki 1|Page
,Qspiders Campus Connect v1.0.0
1.4. C Compilers
When you write any program in C language then to run that program you need to compile
that program using a C Compiler which converts your program into a language
understandable by a computer. This is called machine language (ie. binary format). So before
proceeding, make sure you have C Compiler available at your computer. It comes alongwith
all flavors of Unix and Linux.
If you are working over Unix or Linux then you can type gcc -v or cc -v and check the result.
You can ask your system administrator or you can take help from anyone to identify an
available C Compiler at your computer.
1.5. Execution flow of C program
Source File
(.c extension)
Preprocessor
Extended
Source code
Compiler
Assembly code
(.asm file)
Assembler
Library Object Object code
code (.obj file)
Linker
Executable file
(.exe file)
Vishal C Vanaki 2|Page
,Qspiders Campus Connect v1.0.0
When we execute a C program these are steps that take place.
To execute the c program in Turbo C. press CTRL+F9.
1) The source code will be submitted to the preprocessor. Preprocessor is a software and part
of compiler which extends the source code by adding prototypes of pre-defined functions,
removing comments, replacing macros with its definition, etc.
2) The extended source code will then be submitted to the compiler, which intern generates
the assembly code (.asm).
3) This .asm file will be given as the input to the assembler which generates the object code(
machine readable- .obj file).
4) This object code and the library object codes (object codes of predefined function) will be
linked by the Linker. Then it generates executable file (.exe)
1.6. Syntax of C program
Different programming languages have their own format of coding. The basic components of
a C program are:
• Main()
• A pair of curly braces {,}
• Declarations and statements.
• User-defined functions.
The complete structure of a C program is shown below
Preprocessor_statements
Global_declarations;
main( )
{
Local_declarations;
statements;
}
User_defined_function
Preprocessor statements
These statements begin with # symbol, and are also called the preprocessor directives. These
statements direct the C preprocessor to include header files and also symbolic constants into a
C program.
Vishal C Vanaki 3|Page
, Qspiders Campus Connect v1.0.0
Some of preprocessor statements are given below
#include <stdio.h> : for the standard input/output functions
#include “Test.h” : for file inclusion of header file Test.
#define NULL 0 : for defining symbolic constant, NULL=0
Global Declarations
Variables or functions whose existence is known in the main( ) function and other user
defined functions, are called the global variables (of functions) and their declarations are
called the global declarations. This declaration should be made before main( ) as shown
above.
The main( ) function
As the name itself indicates, this is the main function of every C program. Execution of a C
program starts with main( ). No C program is executed without the main( ) function. The
function main( ) should be written in lower case letters and should not be terminated by a
semicolon. It calls other library functions and user defined functions. There must be one and
only one main( ) function in every C program.
Braces
Every C program uses a pair of curly braces ({,}). The left barce indicates the beginning of
the main() function. On the other hand, the right brace indicates the end of the main()
function. The braces can also be used to indicate the beginning and end of user-defined
functions and the compound statements.
Local declarations
The declaration is a part of the C program where all the variables, arrays, functions etc. used
in the C program are declared and may be initialized with their basic data types.
Statements
These are instructions to the computer to perform some specific operations.
User-defined functions
These are sub programs. The user-defined function contains a set of statements to perform a
specific task.
Vishal C Vanaki 4|Page