1. Introduction to C Language
C Tokens
Structure of C Program
Compiling and Executing a C Program
C Language Preliminaries
Abhineet Anand
Computer Science and Engg. Department
University of Petrolium and Energy Studies, Dehradun
November 19, 2012
Abhineet Anand C Language Preliminaries
2. Introduction to C Language
Introduction
C Tokens
History of C
Structure of C Program
Characteristics of C
Compiling and Executing a C Program
Introduction
C is a high level language.
It also has the capability of low level programming. So,
sometimes also referred as middle level Programming
Language.
Best Programming Language for learning procedural
programming approach.
It was developed at the Bell Laboratory, USA (now AT & T),
in 1972.
It is the outcome of Dennis Ritchie and Brian Kernighan.
Abhineet Anand C Language Preliminaries
3. Introduction to C Language
Introduction
C Tokens
History of C
Structure of C Program
Characteristics of C
Compiling and Executing a C Program
History of C
C is derived from two early programming languages such
as BCPL (Basic Combined Programming Language) and B
language developed by Ken Thompson.
In 1972 Dennis Ritchie developed a new version of B and
named it as C.
In 1978, Dennis Ritchie and Brian Kernighan jointly
published a detailed description of the C language
document. It is Known as K & R C.
Some of Shortcomings of K & R C implementation are
overcome by ANSI (American National Standard Institute)
standards.
Abhineet Anand C Language Preliminaries
4. Introduction to C Language
Introduction
C Tokens
History of C
Structure of C Program
Characteristics of C
Compiling and Executing a C Program
Characteristics of C
C is a general purpose & structured programming
language, which helps in development of system software.
It has rich set of operators.
It provides compact representation for expression.
It allows manipulation of internal processor registers.
Portability: any C program can be run in different machine
with no modification.
Rich set of data types and less number of reserved words.
Pointer arithmetic and manipulation.
Ability to extend itself by adding fuctions to its library.
Abhineet Anand C Language Preliminaries
5. Introduction to C Language
C Tokens C Tokens
Structure of C Program Keywords and Identifiers
Compiling and Executing a C Program
C Tokens
The Basic and Smallest units of any programming
language is known as tokens. When a complier complies a
program, it recognises those basic units.
There are six types of tokens in C. They are:
Keywords
Identifiers
Constants
Strings
Operators
Special Symbols.
Each of these tokens is formed with one or more
charecters of C language.
Abhineet Anand C Language Preliminaries
6. Introduction to C Language
C Tokens C Tokens
Structure of C Program Keywords and Identifiers
Compiling and Executing a C Program
Keywords
Every word in C program is either a keyword or an identifer.
All Keywords must be written in lowercase letters.
C is case sensitive language.
Keywords supported by ANSI C are:
auto, break, case, char, const, continue, default, do,
double, else, enum, extern, float, for, goto, if, int, long,
register, short, signed, sizeof, static, struct, switch, typedef,
union, unsigned, void, volatile & while.
Abhineet Anand C Language Preliminaries
7. Introduction to C Language
C Tokens C Tokens
Structure of C Program Keywords and Identifiers
Compiling and Executing a C Program
Identifiers
Identifiers are the names given to program elements such
as variables, arrays and fuctions.
These are sequence of alphabets and digits.
Rules for forming identifers names:
First charecter must be an alphabet or an underscore.
No special Charecter or punctuation symbols are allowed
except the underscore "_".
No two successive underscore are allowed.
Keywords should not be used as identifiers.
Abhineet Anand C Language Preliminaries
8. Introduction to C Language
Structure of C Program
C Tokens
Preprocessor Statements
Structure of C Program
Declarations
Compiling and Executing a C Program
Structure of C Program
preprocessor statement
global decleration;
main( )
{
decleration;
statement;
}
user defined function
Abhineet Anand C Language Preliminaries
9. Introduction to C Language
Structure of C Program
C Tokens
Preprocessor Statements
Structure of C Program
Declarations
Compiling and Executing a C Program
Preprocessor Statements
Begin with # symbol, also called the preprocessor
directives.
Direct the C preprocessor to include header files and also
symbolic constants into C program. Few Statements :
# include < stdio.h > : for standard input/output functions.
# include "Test.h" : for file inclusion of the header files.
# deifne NULL 0 : for defining symbolic constant, NULL=0
Abhineet Anand C Language Preliminaries
10. Introduction to C Language
Structure of C Program
C Tokens
Preprocessor Statements
Structure of C Program
Declarations
Compiling and Executing a C Program
Global Declarations
Variable or function whose existance is known in main( )
function and other user defined function, are called the
global variable.
Its decleartion is known as global declarations.
Excuation of C program starts with main( ).
Abhineet Anand C Language Preliminaries
11. Introduction to C Language
Structure of C Program
C Tokens
Preprocessor Statements
Structure of C Program
Declarations
Compiling and Executing a C Program
Declarations
Variable Decleration: All Variables, array, function used in
C program are decleared and may be initialized with their
basic data types.
Statements: the instruction to the computer to perform
some specific task. They may be:
Arithmetic Statements.
Input/output Statements.
Control Statements.
Other Statements.
Comments: explantory notes on some instruction, which
are not executed and enclosed with in /* & */.
Abhineet Anand C Language Preliminaries
12. Introduction to C Language
Compiling and Executing a C Program
C Tokens
Standard Procedure
Structure of C Program
Selecting OS
Compiling and Executing a C Program
Compiling and Executing a C Program
Compiling a C program means translating it into machine
language.C Compiler does that for C pragrams.
Various tools are availble which gives the facility of writing,
editing, debugging and excuting C language program.
This type of environment is known as Inetegrated
Development Environment (IDE).
Examples : Turbo C, Borland C/C++, ANSI C and many
more.
Abhineet Anand C Language Preliminaries
13. Introduction to C Language
Compiling and Executing a C Program
C Tokens
Standard Procedure
Structure of C Program
Selecting OS
Compiling and Executing a C Program
Standard Procedure
There are basically five steps in the sucessful execution of a
program:
Creating a program file (Source File).
Saving the program (with .c as extension).
Compliation.
Linking system library function.
Running (executing) the program.
Abhineet Anand C Language Preliminaries
14. Introduction to C Language
Compiling and Executing a C Program
C Tokens
Standard Procedure
Structure of C Program
Selecting OS
Compiling and Executing a C Program
Selecting OS
DOS Platform:
Any of the C program environment may be used which are
IDE.
Unix Platform:
Any of the Unix text editor is used to type the C Program,
with file extention of .c.
Abhineet Anand C Language Preliminaries
15. Introduction to C Language
Compiling and Executing a C Program
C Tokens
Standard Procedure
Structure of C Program
Selecting OS
Compiling and Executing a C Program
Selecting OS cont..
Now, a C compiler is used to complie the program.
Normally, CC complier is availeble in Unix. So,
cc filename.c
This gives the output as a excutable file named a.out.
Now, this excutable file can be run through
./a.out
on command prompt of unix.
Abhineet Anand C Language Preliminaries
16. Introduction to C Language
C Tokens
Structure of C Program
Compiling and Executing a C Program
THANK YOU
Abhineet Anand C Language Preliminaries