C Language Slideshow
C Language Slideshow
C Language Slideshow
Characteristics of C
∀• Small size
∀• Extensive use of function calls
∀• Loose typing -- unlike PASCAL
∀• Structured language
∀•Pointer implementation - extensive use of pointers for
memory, array, structures and functions.
C Program Structure
Preprocessor Commands
Type definitions
Function prototypes -- declare function types
and variables passed to function
Variables
Functions
Creating, Compiling and Running
Your Program
Use any ordinary editor with which you are
familiar to create the file
Source code
Preprocessor
Compiler
Assembly code
Assembler
librarie
s Object code
Link Editor
Executable code
The Preprocessor
The Preprocessor accepts source code as input
and is responsible for
removing comments
code
Assembler
The assembler creates object code
Variables
IF STATEMENT
? OPERATOR
SWITCH STATEMENT
localvariables
functioncode
VOID FUNCTIONS
Structures
Collection of different datatypes.
A structure is a user-defined data type.
A structure is a collection of one or more variables, possibly
of different types, grouped together under a single name
union number
{
short shortnumber;
long longnumber;
double float number;
}
* POINTERS
What is a Pointer?
A pointer is a variable which contains the address in memory of another
variable .
Dynamic Memory Allocation
Malloc
Calloc
Realloc
FILES
Files are the most common form of a stream
Open a file:
FILE *fopen(char *name, char *mode)
fopen returns a pointer to a FILE.
*name ?? *mode ??
• This representation and the operations that are allowed for it are called
data structures.
• Stacks
• Queues
Lists
Trees
Graphs
Tables
SORTING TECHNIQUES
Bubble sort
Quick sort
Insertion sort
Selection sort
Heap sort