×
DREAM IT. BELIEVE IT. ACHIEVE IT.
--Your friends at LectureNotes
Close

Data Structure using C

by Gopirajan P V
Type: NoteDownloads: 1Views: 92Uploaded: 27 days agoAdd to Favourite

Share it with your friends

Suggested Materials

Leave your Comments

Contributors

Gopirajan P V
Gopirajan P V
EC8393 FUNDAMENTALS OF DATA STRUCTURES IN C EC8393 FUNDAMENTALS OF DATA STRUCTURES IN C UNIT I C PROGRAMMING BASICS Introduction to ‘ C’ programming –fundamentals – structureof a ‘C’ program – compilation and linking processes – Constants, Variables – Data Types –Expressions using operators in ‘C’ – Managing Input and Output operations – Decision Making and Branching – Looping statements – Arrays – Initialization – Declaration – One dimensional and Two-dimensional arrays. Strings- String operations – String Arrays. Simple programs- sorting- searching – matrix operations. 1.1 Introduction to C:  C is a general-purpose programming language.  It has been developed by Dennis Ritchie at Bell Laboratories in 1972.  C as evolved from the earlier languages Basic combined Programming Language (BCPL) called B.  C was developed for the Unix operating system. It was first implemented on the Digital Equipment Corporation PDP-11 computer in 1972.  C runs under number of OS including MS-DOS  C is a middle level language i.e.it supports both the low-level language and high-level language features.  C is a structured language. A structured language allows variety of programs in small modules.  It is easy for debugging, testing and maintenance of a program.  Programming with structured language is efficient and fast due to modular approach.  C is having the highest degree of portability across the various hardware platforms.  C is powerful, efficient, compact and flexible. Overview of compilers and interpreters:  A Program is a set of instructions for performing a particular.  The written program is calledas source program.  The program converted to the machine language is known as object program.  Either interpreter or compiler will perform this function. Interpreters:  An interpreter reads only one line of a source program at a time and converts it to object codes.  In case of any errors, the errors will be indicated instantly.  Disadvantage o Takes more time to convert a source program to an object program. Compilers:  A compiler reads the entire program and convert it to the object program.  It provides errors of the entire program.  It consumes little time for converting a source program to an object program. 1.2 Structure of a c program:  C program consists of a number of building blocks called functions.  A function is a subroutine that may include one or more statements.  Each function performs a specific task.  File with the same file name extension “.obj”.  Example: hello.c and hello.obj Fig: Structure of a c program 1
EC8393 FUNDAMENTALS OF DATA STRUCTURES IN C Documentation section Link Section Global declaration section Main() /*function name */ { Declaration part; Executable part; } Sub Program function/* user defined */ Function 1 Function 2 . . Function n Document Selection:  It consists of a set of commend lines giving the name of the program, the author and other details.  It is optional. Link Selection:  It provides instrutions to the compiler to link function from the system library.  To link the function 'c' program depands upon some header files.  Each header file by extended with .h.  The header file should include using #include directires. Example <stdio.h> -Input/Output funtions <conio.h> -Clear Screen function <math.h> -Mathematics function <string.h>- String function <time.h> -Date and Time function <stdlib.h> -Library function Global declaration section:  This section declares variables used in more than one functions, known as global variables.  This section must be declared outside of all function. Comments  Comments are (optional) in the program.  It is used for understand the flow of program easily.  Comments are not processed by the compiler  There are 2 types of comment 1. Single line comment 2. Multi line comment i) Single line comment  it starts with two forward slashes(//) and automatically terminates at the end of the line  Example; //single comment ii) Multi line comment  start with /* and terminate with */ 2
EC8393 FUNDAMENTALS OF DATA STRUCTURES IN C  Example: /* multi line Comment */ main() function section  Every C program must have one main() funtion.  The program will always begin by executing the main function.  This selection contains 2 parts i) Declaration part and ii) Executable part. i) Declaration part:  The declaration part declares all the variables used in the executable part.  The initialization of variables are also done in this selection. ii) Executable part:  There is at least one statement is the executable part.  These two parts must appear between the opening braces and closing braces. All statements in the declaration & executable part and with a semicolon (;). Subprogram Selection  It contain all the user-defined function that are called in the main() function.  These function are generally defined immediately after the main function 1.3 Programming Rules  The Program execution starts at main()  All statements should be written in lower case letter. Constants and variables can be written in upper case letters.  Blank spaces may be inserted between words accept for declaring keywords, variables, constant and function.  The user can write one or more statements in one line by separating then with a semicolon(;).  Example: a=b; d=b+c; (or) a=b; d=b+c  The opening and closing braces should be balanced.  Example: if opening braces are 4, then closing braces should also be four. 1.4 Executing a C program  Execution of a C program involves a series of steps.  They are 1. Creating the program 2. Compiling the program 3. Linking the program 4. executing the program 1) Creating the program  Program should be written in c editor.  The file name should include the extension .c.  Example: Hello.c Program.c 3
EC8393 FUNDAMENTALS OF DATA STRUCTURES IN C 2) Compiling the program  The source program statements are translated into object programs.  The translation is done after correcting each statement.  If there is no error, the compilation proceeds and translated program stored in a 3) Linking the program:  Linking keeps all program files and functions required by the program together.  For example if the programmer is using pow() function,then the object code of the function should be brought from the math library (math.h) of the system and linked to the main program. 4) Executing the program:  After the compilation, the executable object code will be loaded in the computer’s main memory and the program is executed.  In case of logic or data errors in the program, it would be necessary to correct the source program or the data, and repeat compiling, linking and executing the program. Character set:  The character that can be used to form words,numbers and expressions depend upon the computer on which the program runs.  The characters in c are grouped into following categories: 1. Letters (Both uppercase letter A to Z ,Lowercase Letter a to z) 2. Digits (number for 0 to 9) 3. Special characters 4. White Space  Blank space  Horizontal tab(‘\t’)  Carriage return  New line (‘\n’)  Form feed Special character Symbols , . ; : ? ‘ “ ! | / \ ~ _ $ % Name Comma Dot or Period Semicolon Colon Question mark Apostrophe Question mark Exclamation mark Vertical bar Slash Back slash Tilde Underscore Dollar Percent sign Symbols & ^ * + < > ( ) { } [] @ # = 4 Name Ampersand Caret Asterisk Plus sign Minus sign Less than Greater than Left Parenthesis Right Parenthesis Left Curley braces Right Curley braces Square bracket ( Left / Right) At the rate Hash Equal to

Lecture Notes