2. INTRODUCTION
C language was evolved from ALGOL,BCPL
and B by Dennis Ritchie at bell laboratories in
1972.
It has been developed to re-implement the
Unix operating system. It has since become one
of the most widely used programming
languages of all time.
To ensure that C language remains standard in
1983 American National Standards Institute
approved a version of c which is also referred to
as C89.
3. DENNIS RITCHIE
The c standardization
committee felt that a few
features of c++ and java if
added to c it would enhance
the usefulness of language.
The result was the 1999
standard for c .This version
is usually referred to as c99.
4.
5. FEATURES OF C LANGUAGE:
It is a robust language and has a rich set of built
in functions .
C provides a wide range of data types ,
operators and functions which makes its code
highly efficient and fast.
C is a compatible language and can run on all
machines right from 8088 to recent machines.
C has only 32 keywords.
6. C is simple to implement and is highly effective.
C supports pointers which can directly access
the address of a variable in computers memory.
C provides Modular programming: It is a logical
collection of one or more functions or modules
C provides Dynamic Allocation of Memory :
This allows to allocate memory during runtime .
C is a middle level language.
C is extensible: It continuously adds the library
functions supported by c library.
7.
8. STRUCTURE OF C PROGRAM
Documentation Section
Link Section
Definition Section
Global Declaration Section
main() Function Section
{
}
Subprogram Section:
Declaration part
Executable part
Function 1
Function 2
-
-
Function n
9. DOCUMENTATION SECTION:
It consists of a set of comment lines giving the
name of the program, the author and other
details, which the programmer would like to use
later.
LINK SECTION:
It provides instructions to the compiler to link
functions from the system library.
We include definite predefined standard library
functions in our C program and all these different
library functions are available in standard header
files.
10. DEFINITION SECTION:
Definition section defines all symbolic constants
like #define PI 3.14
GLOBAL DECLARATION SECTION:
It declares Global variables.This section also
declares user defined functions.
Global variables are the variables that are used in
more than one function and are declared in global
declaration section that is outside of all the
functions.
main() function section:
Every c program must have only one main
function. It indicates the beginning of program.
11. If the program contains more than one main
function the compiler cannot tell which one
marks the beginning of the program.
This section contains two parts:
Declaration part:
It declares all the variables used in executable
part.
Executable part :
There is only one statement in executable
part. It consists of statements which need to be
executed.
The program execution begins at opening
brace and ends at closing brace.
12. All statements in declaration and executable
part must end with semicolon i.e. ;.
Subprogram Section:
It contains all the user defined functions that
are called in the main function.
They are generally placed immediately after
main function although they may appear in any
order .
13. COMMENTS
Comments are used in the program to improve the
readability and understanding.
Comments are not executed by the compiler, they are
ignored by the compiler.
It helps the programmers to understand the various
operations of a program and serve as an aid to debugging
and testing.
Single line comments start with// symbol and multiple line
comments are written within /*and /*.
14. Header files
The files that are specified in the include
section is called as Header File.
These are precompiled files that has some
functions defined in them.
We can call those functions in our program
by supplying parameters.
Header file is given an extension .h.
C source file is given an extension .c.
16. Constants Examples
Integer Constants
o Refers to sequence of digits such as decimal integer, octal integer and
hexadecimal integer.
o Some of the examples are 112, 0551, 56579u, 0X2 etc.
Real Constants
o The floating point constants such as 0.0083, -0.78, +67.89 etc.
Single Character Constants
o A single char const contains a single character enclosed within a pair of
single quotes[ ‘ ‘ ]. For example, ‘g’, ‘a’, ‘I’ etc.
String Constants
o A string constant is a sequence of characters enclosed in double quotes
[ “ “]; For example, “0211”, “Stack Overflow” etc.
17. AVariables is a data name that is used to store any
data value.
Variables are used to store values that can be changed
during the program execution.
Variables in C have the same meaning as variables in
algebra.That is, they represent some unknown, or
variable, value.
x= a+b
z+2 = 3(y-5)
Remember that variables in algebra are represented
by a single alphabetic character.
What Are Variables in C?
18. Variables in C may be given representations containing multiple
characters. But there are rules for these representations.
Variables names in C:
May only consist of letters, digits, and underscores
May be as long as you like, but only the first 31 characters are
significant
May not be a C reserved word (keyword)
Should start with a letter or an underscore(_)
Can contain letters, numbers or underscore.
No other special characters are allowed including
space.
Naming Variables
19. Before using a variable , you must give the
compiler some information about the
variable; i.e., you must declare it.
The declaration statement includes the data
type of the variable.
Example of variable declarations:
int length;
float area;
Declaring Variables
20. Variables are not automatically initialized. For
example, after declaration
int sum;
the value of the variable sum can be
anything (garbage).
Thus, it is a good practice to initialize variables
when they are declared.
Once a value has been placed in a variable it
stays there until the program alters it.
Declaring Variables
22. Size and Range of Data Types
TYPE SIZE (Bits) Range
Char or Signed Char 8 -128 to 127
Unsigned Char 8 0 to 255
Int or Signed int 16 -32768 to 32767
Unsigned int 16 0 to 65535
Short int or Signed short
int
8 -128 to 127
Unsigned short int 8 0 to 255
Long int or signed long int 32 -2147483648 to
2147483647
Unsigned long int 32 0 to 4294967295
Float 32 3.4 e-38 to 3.4 e+38
Double 64 1.7 e-308 to 1.7 e+308
Long Double 80 3.4 e4932 to 3.4 e+4932