Presentation is loading. Please wait.

Presentation is loading. Please wait.

C LANGUAGE Characteristics of C · Small size

Similar presentations


Presentation on theme: "C LANGUAGE Characteristics of C · Small size"— Presentation transcript:

1 C LANGUAGE 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.

2 C Program Structure Preprocessor Commands Type definitions
Function prototypes -- declare function types and variables passed to function Variables Functions

3 Creating, Compiling and Running Your Program
Use any ordinary editor with which you are familiar to create the file The filename must by convention end ``.c'' (full stop, lower case c), e.g. myprog.c

4 The C Compilation Model
Source code Preprocessor Compiler Assembly code Assembler libraries Object code Link Editor Executable code

5 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

6 Variables C type Size (byte) Unsigned char 1 Short int 2
Unsigned short int (long) int float double

7 Arithmetic Operations
Increment & Decrement operations Postfix and Prefix expressions example:- x++ is faster than x=x+1.

8 Order of Precedence () [ ] -> . * / % + - < <= >= >
() [ ] -> . * / % + - < <= >= > == != & ^ && || ,

9 CONDITIONALS IF STATEMENT ? OPERATOR SWITCH STATEMENT
break and continue C provides two commands to control how we loop: ·         break -- exit form loop or switch. continue -- skip 1 iteration of loop

10 FUNCTIONS { localvariables functioncode } VOID FUNCTIONS
returntype fn_name(1, parameterdef2,…) { localvariables functioncode } VOID FUNCTIONS

11 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 ;

12 UNIONS A union is a variable which may hold (at different times) objects of different sizes and types . union number { short shortnumber; long longnumber; double float number; }

13 * 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 memory of another variable .

14 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

15 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..)

16 Basic String Handling Functions
strcmp strcat strcpy strlen strerror strcasecmp

17 DATA STRUCTURES Definition of data structures
• Many algorithms require that we use a proper representation of data to achieve efficiency. • This representation and the operations that are allowed for it are called data structures. • Each data structure allows insertion, access, deletion etc.

18 Why do we need data structures?
• Data structures allow us to achieve an important goal: component reuse • Once each data structure has been implemented once, it can be used over and over again in various applications.

19 Common data structures are
• Stacks • Queues Lists Trees Graphs Tables

20 SORTING TECHNIQUES Bubble sort Quick sort Insertion sort
Selection sort Heap sort


Download ppt "C LANGUAGE Characteristics of C · Small size"

Similar presentations


Ads by Google