3. History of ‘c’
Features of ‘c’
Structure of program
Header files
Main function
Data type
Constant
Variables
Operators
Input/output
C preprocessor
Om Institute of Technology 3
4. Om Institute of Technology 4
C is developed by Dennis Ritchie
C is a structured programming language
C supports functions that enables easy maintainability of
code, by breaking large file into smaller modules
Comments in C provides easy readability
C is a powerful language
5. Om Institute of Technology 5
Important feature of ‘C’ language is it is portable, by
portability we mean that the program can be run on any
hardware machine.
It supports modular programming.
It supports bit-wise operations.
It is known as structured programming language.
6. Om Institute of Technology 6
Documentation Section //optional
Link section //optional
Defining section //optional
Global declaration section //optional
Main function section //Must
{
Declaration part
Executable part.
}
Sub program section //optional
Function 1
Function 2
.
.
Function n
7. Om Institute of Technology 7
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
8. Om Institute of Technology 8
This is the entry point of a program
When a file is executed, the start point is the main function
From main function the flow goes as per the programmers
choice.
There may or may not be other functions written by user in a
program
Main function is compulsory for any c program
9. Om Institute of Technology 9
A data type in a programming language is a set
of data values having predefine characteristics.
there are three classes of data types:
Data Type
Primitive derived user define
10. Om Institute of Technology 10
Primitive data types
int, float, double, char
Aggregate data types
Arrays come under this category
Arrays can contain collection of int or float or char or
double data
User defined data types
Structures and enum fall under this category.
11. Om Institute of Technology 11
The ‘C’ language supports following types of
constants:
Numeric constants (5, 15, 3.6, -5.4 etc)
Non-numeric constants
Character constants (‘B’ , ‘a’ , ‘?’ , ‘5’ , ‘+’ etc)
String Constants (“Computer”, “XYZ”, “-5.4” etc)
12. Om Institute of Technology 12
a Bell
b Back space
f Form feed
n New line
r Carriage return
t Horizontal tab
v vertical tab
’ single quote
” Double quote
? Question Mark
Backslash
0 Null
13. Om Institute of Technology 13
Variables are the identifiers whose value changes as opposite
to constants.
As variable is an identifier, all the rules for naming an
identifier applies to variables also.
Should not be a reserved word like int etc..
Should start with a letter or an underscore(_)
Can contain letters, numbers or underscore.
No other special characters are allowed including space
Variable names are case sensitive
A and a are different.
14. Om Institute of Technology 14
Arithmetic (+,-,*,/,%)
Relational (<,>,<=,>=,==,!=)
Logical (&&,||,!)
Bitwise (&,|)
Assignment (=)
Compound assignment(+=,*=,-=,/=,%=,&=,|=)
Shift (right shift >>, left shift <<)
15. Om Institute of Technology 15
Input
scanf(“%d”,&a);
Gets an integer value from the user and stores it under
the name “a”
Output
printf(“%d”,a);
Prints the value present in variable a on the screen
16. Om Institute of Technology 16
All preprocessor directives begin with #
Possible actions
Inclusion of other files
Definition of symbolic constants & macros
Conditional compilation of program code
Conditional compilation of preprocessor directives
Format specifiers
%d is the format specifier. This informs to the compiler that the incoming value is an integer value.
Other data types can be specified as follows:
%c – character
%f – float
%lf – double
%s – character array (string)
Printf and scanf are defined under the header file stdio.h