0% found this document useful (0 votes)
363 views14 pages

C Programming & Data Structures Course

The document describes a course on Programming in C and Data Structures. The objectives of the course are to learn the basics of C programming, control structures, arrays, pointers, strings, files, and basic data structures. The course is divided into 6 units that cover topics such as basic C concepts, loops, arrays, pointers, strings, files, stacks, queues, linked lists, and trees. References for further reading are provided. Upon completing the course, students will be able to develop C programs, use arrays and functions, solve problems, manipulate files, and understand basic data structures concepts.

Uploaded by

malathi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
363 views14 pages

C Programming & Data Structures Course

The document describes a course on Programming in C and Data Structures. The objectives of the course are to learn the basics of C programming, control structures, arrays, pointers, strings, files, and basic data structures. The course is divided into 6 units that cover topics such as basic C concepts, loops, arrays, pointers, strings, files, stacks, queues, linked lists, and trees. References for further reading are provided. Upon completing the course, students will be able to develop C programs, use arrays and functions, solve problems, manipulate files, and understand basic data structures concepts.

Uploaded by

malathi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Prepared by Dr.S.Malathi, Asst.

Prof of CS, Swami Dayananda College of Arts & Science, Manjakkudi

CORE COURSE I
PROGRAMMING IN C AND DATA STRUCTURES
Semester I

Code: (Theory) Credit: 5

COURSE OBJECTIVES:
 To know about the basics of C Programming, Control and Looping
 Structures and programming with it.
 To understand Arrays, Pointers and String Processing in C
 language
 To know about the basic concepts in Data Structures.

UNIT - I:
Basic of C: History of C and its importance – Structure of a C program – Data
Types – Constants and Variables – Operators and Expressions – Order of
Precedence, Evaluating of Arithmetic Expressions – Type Conversion- Decision
Statements: if, if-else, and nested if statements.

UNIT - II:
Loops Structures: For Loop, While, Do-while loop – Arrays: - One Dimensional
Array, Two-dimensional Arrays, Character Arrays and Strings – Functions:
Function with arrays - Function with decision and looping statements -
Recursion.

UNIT - III:
Pointers: Introduction – Pointer Expressions – Chain of Pointers – Pointers and
Arrays – Array of Pointers – Pointers as function arguments – Functions
returning Pointers – Pointers to Functions – Function pointer – Structures -
declaration, initialization, Array of Structures – Pointer to structures, Structures
and functions – Typed of Enumerated data types, Unions.

UNIT - IV:
Strings Processing, Standard string library functions – Files: introduction and
files functions – Writing and reading in Text mode – Simple application:
Display the contents of a file. Write data to a file. Append data to an existing
file – File IO– Reading and writing structures.

1
Prepared by Dr.S.Malathi, Asst.Prof of CS, Swami Dayananda College of Arts & Science, Manjakkudi

UNIT - V:
Stack: LIFO concept, Stack operations, Array implementation of stack – Queue:
FIFO concept, Queue operations, Array implementation of queue – Singly
Linked List: concepts, operations – Doubly Linked List: concepts, operations –
Trees: General trees, Binary trees.

UNIT – VI CURRENT CONTOURS (For continuous internal assessment


only):
Contemporary Developments Related to the Course during the Semester
Concerned.

REFERENCES:
1. E. Balagurusamy, “Programming in ANSI C”, Tata McGraw Hill, New
Delhi, Seventh Edition, 2016.
2. E.Horowitz, S.Sahni and Susan Anderson Freed, “Fundamental Data
Structures in C”, 2ed, Orient BlackSwan Publisher, 2009.
3. Byron S. Gottfried, “Programming with C”, Schaum’s Outline Series, Tata-
McGraw Hill Edition, New Delhi, 1991.
4. E. Karthikeyan, “A Textbook on C Fundamentals, Data Structures and
Problem Solving”, Prentice-Hall of India Private Limited, New Delhi, 2008.
5. Yashavant Kanetkar, “Let us C”, BPB Publications, Tenth Edition, New
Delhi, 2010.
6. Szuhay, Jeff, and Szuhay, Jeff, “Learn C Programming: A Beginner's Guide
to Learning C Programming the Easy and Disciplined Way”, Packt Publishing,
2020.
7. Jena, Sisir Kumar, and Jena, Sisir Kumar, “C Programming: Learn to Code”,
CRC Press, 2021.
8. https://www.tutorialspoint.com/cprogramming/index.htm
9. https://www.w3schools.in/data-structures/intro

COURSE OUTCOMES:
Upon successful completion of this course the students would be able to:
 Summarize the basic knowledge to develop C programs
 Manipulate Looping, arrays and functions
 Apply and write programs for solving real world problems
 Create open, read, manipulate, write and close files.
 Understand the basic concepts in data structures.

2
Prepared by Dr.S.Malathi, Asst.Prof of CS, Swami Dayananda College of Arts & Science, Manjakkudi

UNIT – I
Basic of C: History of C and its importance – Structure of a C program – Data
Types – Constants and Variables – Operators and Expressions – Order of
Precedence, Evaluating of Arithmetic Expressions – Type Conversion- Decision
Statements: if, if-else, and nested if statements.

HISTORY OF C
C language is one of the most popular computer languages today because it is a
structured, high level, machine independent language. It allows software
developers to develop software without worrying about the hardware platforms
where they will be implemented.   
 The root of all modem languages is ALGOL, introduced in the early
1960s. ALGOL was the first computer language to use a block structure. 
 From ALGOL, Martin Richards developed a type less language called
BCPL (Basic Combined Programming Language). This was also a high-
level computer language.
 In 1970, Ken Thompson created a language using BCPL called B, which
was also type less.
 Then, Dennis Ritchie at AT&T Bell Labs took the development of C into
his hands. Using the foundations laid down by previous languages BCPL
and B, he developed the C programming language in 1972.
 C was initially used to re-implement the UNIX operating system, which
was rewritten in C from assembly language, and it quickly gained
popularity for its portability and efficiency. So, the development of the
UNIX operating system started in 1969. And in the year 1972, its code
was rewritten in the C programming language.
 In 1985, windows 1.0 was released, and while its source code is not
publicly available, it has been stated that its kernel is mostly written in K
programming language.
 Linux, a popular operating system, started its development in 1991 using
C programming language and Lisp. After almost a year of development,
it was released under the GNU license and was used as part of the GNU
operating system.
 Oracle, the most widely used relational database management
system (RDBMS), began its development in 1977. In 1983, its code was
rewritten from assembly language to C programming language.

3
Prepared by Dr.S.Malathi, Asst.Prof of CS, Swami Dayananda College of Arts & Science, Manjakkudi

IMPORTANCE OF C LANGUAGE
 It is a robust language whose rich set of built in functions and operators can
be used to write any complex program.
 The C compiler combines the capabilities of an assembly language with
features of a high level language and therefore it is well suited for writing
both system software and business packages.
 Programs written in C are efficient and fast. This is due to its variety of data
types and powerful operators.
 There are only 32 keywords in ANSI C
 It has more built-in functions, which can be used for developing programs.

4
Prepared by Dr.S.Malathi, Asst.Prof of CS, Swami Dayananda College of Arts & Science, Manjakkudi

 C is highly portable. This means that C programs written for one computer
can be run on another with little or no modification. 
 C language is well suited for structured programming, this requiring the
user to think of a problem in terms of function modules or blocks. A proper
collection of these modules would make a complete program.
 Another important feature of C is its ability to extend itself. A C program is
basically a collection of functions that are supported by the C library.

STRUCTURE OF A C PROGRAM
The structure of a program is defined by its control flow, as structures are built
up of blocks of codes. These blocks have a single entry and exit in the control
flow. The basic structure of a C program is divided into 6 parts which makes it
easy to read, modify, document, and understand in a particular format. C
program must follow the below-mentioned outline in order to successfully
compile and execute. Debugging is easier in a well-structured C program.

DOCUMENTATION SECTION:
This section consists of the description of the program, the name of the
program, and the creation date and time of the program. It is specified at the
start of the program in the form of comments.  It gives an overview to the reader
of the program.

5
Prepared by Dr.S.Malathi, Asst.Prof of CS, Swami Dayananda College of Arts & Science, Manjakkudi

Method 1: // - This is use to write a single line comment.


Method 2: /* */ - This is used to write multi-line comments.

Example
// description, name of the program, programmer name, date, time

/*
Description
Name of the program
Programmer name
Date
Time
*/

LINK SECTION:
The link section is called as preprocessor directives. The link section consists of
the header files of the functions that are used in the program. It provides
instructions to the compiler to link functions from the system library.
Example
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<string.h>

DEFINITION SECTION:
The definition section is also called as preprocessor directives. All the symbolic
constants are written in definition section. Macros are known as symbolic
constants. It is defined using the #define directive.
Example
#define PI 3.14
#define TRUE 1
GLOBAL DECLARATION SECTION:
Some variables are used in more than one function. Such variables are called
global variables and are declared in the global declaration section that means
declared outside of the functions. It can be used anywhere in the program. 
Example
int mark1, mark1;

6
Prepared by Dr.S.Malathi, Asst.Prof of CS, Swami Dayananda College of Arts & Science, Manjakkudi

MAIN() FUNCTION SECTION:


Every C program must have a main function. The main() function of the
program is written in this section. Operations like declaration and execution are
performed inside the curly braces of the main program. The return type of the
main() function can be int as well as void too. The void() main tells the
compiler that the program will not return any value. The int main() tells the
compiler that the program will return an integer value.
Example
Void main()
{
}
SUBPROGRAM SECTION:
User-defined functions are called in this section of the program. The control of
the program is shifted to the called function whenever they are called from the
the main() function. These are specified as per the requirements of the
programmer. 
Example
sum(int y) 
{
 return y + X;
}

Example Program
// Documentation
/*                    
  File: sum.c
  Author: I CS
Description: program to find sum.
 */
  
// Link
#include <stdio.h>      
  
// Definition
#define X 20 
  
// Global Declaration
int sum(int y);   

7
Prepared by Dr.S.Malathi, Asst.Prof of CS, Swami Dayananda College of Arts & Science, Manjakkudi

 // Main() Function


void main()     
{
  int y = 55;
  printf("Sum: %d", sum(y));
}
  
// Subprogram
int sum(int y) 
{
  return y + X;
}
EXECUTING A C PROGRAM
Steps involved in the Compilation and execution of a C program:
1. Creating the Program (Shortcut key : F2)
2. Compiling the program (Shortcut key : alt+F9)
3. Linking the program with functions that are needed from the C library.
4. Execution of the program (Shortcut key :ctrl +F9)

CHARACTER SET
Character set refers to a set of all the valid characters that is used in the source
program for forming words, expressions, and numbers. Characters in C are
classified into 4groups.
 Letters:
Upper case: A to Z
Lower case: a to z
 Digits:
C program support 10 (0 to 9) digit which are used to construct numerical
value.
 White space characters:
White Space Meaning White Space Meaning
\b blank space \\ back slash
\t horizontal tab \’ single quote
\v vertical tab \” double quote
\r carriage \? Question mark
return
\f form feed \0 null
\n new line \a alarm (bell)

8
Prepared by Dr.S.Malathi, Asst.Prof of CS, Swami Dayananda College of Arts & Science, Manjakkudi

 Special characters:
C programming supports set of special symbols that include symbols to perform
mathematical operation, check condition and other special symbol.

Trigraph characters
Keyboards may not have keys to cover the entire character set of the language.
Trigraph characters are used to provide a way to enter certain characters that are
not available on some keyboards.
A trigraph is a sequence of three characters, the first two are question marks
followed by a character.
Trigraph characters Translation Meaning
??= # Number sign
??/ \ Back slash
??' ^ caret
??( [ Left bracket
??) ] Right bracket
??! | Vertical bar
??< { Left braces
??> } Right braces
??- ~ tilde

9
Prepared by Dr.S.Malathi, Asst.Prof of CS, Swami Dayananda College of Arts & Science, Manjakkudi

TOKENS
In a passage of text individual words and punctuation marks are called tokens.
Smallest individual unit of a program is known as token.
A C program consists of various tokens and a token is either a keyword, an
identifier, a constant, a string literal, or a symbol. For example, the following C
statement consists of five tokens:
printf("Hello, World! \n");
These individual tokens are:
1. Printf
2. (
3. "Hello, World! \n"
4. )
5. ;
C has 6 types of tokens.

1. Keywords
2. Identifiers
3. Constants
4. Strings
5. Operators
6. Special symbols

KEYWORDS
Every c word is classified as either a keyword or an identifier. All keywords
have fixed meanings and these meanings cannot be changed. It serves as basic
building blocks of program statements.

Keywords are predefined, reserved words in C and each of which is associated


with specific features. They have special meaning to the compilers. There are
totally 32 keywords in C.

auto double int struct

break else long switch

case enum register typedef

char extern return union

10
Prepared by Dr.S.Malathi, Asst.Prof of CS, Swami Dayananda College of Arts & Science, Manjakkudi

continue for signed void

do if static while

default goto sizeof volatile

const float short unsigned

IDENTIFIERS
Identifiers refer to the names of variables, functions and arrays. Each program
element in C programming is known as an identifier. They are used for naming
of variables, functions, array etc. These are user-defined names which consist
of alphabets, number, underscore. Identifier’s name should not be same or same
as keywords. Keywords are not used as identifiers.
Rules for naming C identifiers:
 It must begin with alphabets or underscore.
 Only alphabets, numbers, underscore can be used, no other special
characters, punctuations are allowed.
 It must not contain white space.
 It should not be a keyword.
 It should be up to 31 characters long.

CONSTANTS

STRINGS
A string is an array of characters ended with a null character (\0). This null
character indicates that string has ended. Strings are always enclosed with
double quotes(“ ”)
Let us see how to declare String in C language
 char string[20] = {‘s’,’t’,’u’,’d’,’y’, ‘\0’};
 char string[20] = “demo”;
 char string [] = “demo”;
Here is an example of tokens in C language,

11
Prepared by Dr.S.Malathi, Asst.Prof of CS, Swami Dayananda College of Arts & Science, Manjakkudi

OPERATORS
An operator is a symbol that operates on a variable or value. It is used for
performing certain operations like arithmetical, logical, relational, etc. The
purpose of operators is mainly for mathematical and logical calculations.

Types of Operators in C
In C, there are 8 types of operators available to perform various operations.
1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Conditional Operator 
5. Assignment Operators 
6. Increment & Decrement operators
7. Bitwise Operator 
8. Special Operators

1. Arithmetic Operators
The purpose of this operator is to perform mathematical operations like
addition, subtraction, division, multiplication etc. This type of operators is
called Binary Operators. This type of operator works with two operands.

Operator Description Example


+ Addition between 2 operands. A + B = 10
− Subtraction between 2 operands. A−B=0
* Multiplication between 2 operands. A * B = 25
/ Division between 2 operands. B/A=1
% It returns remainder of an integer division. B%A=0

2. Relational Operators
These operators are mainly used for checking relationships between operands.
With the help of this operator, check whether one operand is equal to or greater
than the other operand or not. It returns 1 when the relation is true and when it is
false, it returns 0.

Operator Description Example


== Equal to 5= =5 returns 1
> Greater than 5>6 returns 0
< Less than 6<7 returns 1
>= Greater than equal to 2 >= 1 returns 1
<= Less than equal to 1 <= 2 returns 1
!= Not equal to 5 != 6 returns 1

12
Prepared by Dr.S.Malathi, Asst.Prof of CS, Swami Dayananda College of Arts & Science, Manjakkudi

3. Logical Operators
Logical operators are mostly used for decision making. A logical operator
returns either 0 or 1 whether the condition is true or false.
Operator Description Example
&& (Logical AND) True only if all conditions satisfy. If (8>5 && 7>5) returns 1
|| (Logical OR) True only if either one condition If(3>5 || 9>8) returns 1
satisfies.
! (Logical Not) True only if the operands are not If( 5 != 6) returns 1
equal.

4. Conditional Operator 

5. Assignment Operators 

6. Increment & Decrement operators


This type of operator is called Unary Operators which is works with a single
operand like ++ and – –.

7. Bitwise Operator 

13
Prepared by Dr.S.Malathi, Asst.Prof of CS, Swami Dayananda College of Arts & Science, Manjakkudi

8. Special Operators

DATA TYPES

14

You might also like