Professional Documents
Culture Documents
Smallsize
Extensiveuseoffunctioncalls
Loosetyping--unlikePASCAL
Structuredlanguage
Pointerimplementation-extensiveuseofpointersfor
memory,array,structuresandfunctions.
C Program Structure
Preprocessor Commands
Type definitions
Function prototypes -- declare function types
Source code
Preprocessor
Compiler
Assemblycode
Assembler
librarie
s
Objectcode
LinkEditor
Executablecode
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
char
Unsigned char
Short int
Unsigned short int
(long) int
float
double
Size (byte)
1
1
2
2
4
4
8
Arithmetic Operations
Increment & Decrement operations
Postfix and Prefix expressions
example:- x++ is faster than x=x+1.
Order of Precedence
()
[ ] -> .
* / %
+ < <= >= >
== !=
&
^
&&
||
,
CONDITIONALS
IF STATEMENT
? OPERATOR
SWITCH STATEMENT
FUNCTIONS
returntypefn_name(1,parameterdef2,)
{
localvariables
functioncode
}
VOIDFUNCTIONS
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
Eg: struct student
{
int rollno;
char name[10];
float marks;
}s;
UNIONS
A union is a variable which may hold (at different times)
* POINTERS
C uses pointers a lot. Why?:
It is the only way to express some computations.
It produces compact and efficient code.
It provides a very powerful tool.
What is a Pointer?
A pointer is a variable which contains the address in
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 ??
Reading and writing files
The functions fprintf and fscanf a commonly used to access
files.
int fprintf(FILE *stream, char *format, args..)
int fscanf(FILE *stream, char *format, args..)
strcmp
strcat
strcpy
strlen
strerror
strcasecmp
DATA STRUCTURES
Definition of data structures
SORTING TECHNIQUES
Bubble sort
Quick sort
Insertion sort
Selection sort
Heap sort