Professional Documents
Culture Documents
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
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
• interpreting special preprocessor directives
denoted by #.
C Compiler
• The C compiler translates source to assembly
code
Assembler
• The assembler creates object code
Variables
C type Size (byte)
char 1
Unsigned char 1
Short int 2
Unsigned short int 2
(long) int 4
float 4
double 8
Arithmetic Operations
• Increment & Decrement operations
• 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
Dynamic allocation is a pretty unique feature to C .
It enables us to create data types and structures of any size and length to suit
our programs need within the program.
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