PSD Unit-1
PSD Unit-1
Srikakulam Campus
23CS1181
2
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Course Content Contd..
3
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Course Outcome
4
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Assessment Method
5
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Unit-1
Introduction
6
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
The computer has mainly has two major
components:
Hardware
Software
7
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Computer Hardware
8
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Categories of Computer Hardware
Here are four main categories of computer
hardware:
Input devices
Output devices
Storage devices
Internal components
9
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Input Devices
Input devices allow the user to interact with the
computer.
Examples of input devices include:
Keyboard
Mouse
Scanner
Microphone
Webcam
10
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Output Devices
Printer
Speakers
11
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Storage Devices
12
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Internal Components
Motherboard
13
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Conclusion
14
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Bits and Bytes
15
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
History of Programming Languages
In the computer world, we have about 500+
programming languages with having their own syntax
and features.
• 1949: Assembly Language
• 1952: Autocode
• 1957: FORTRAN
• 1958: ALGOL
• 1959: COBOL
• 1964: BASIC
• 1972: C
• 1972: SQL
• 1978: MATLAB
• 1983: Objective-C, C++
• 1991: Python
• 1995: JAVA, PHP, JavaScript
• 2000: C#
• 2011: Kotlin
• 2014: Swift 16
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Computer Languages
17
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
• There are two main categories:
• High-level languages (like Python, Java) are
closer to human languages, making them easier
to learn and use.
18
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Creating and Running Programs
19
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Creating Source Code
20
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Creating Source Code
21
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Compiling Source Code
What is Compilation?
- Compilation is the process of translating the code from high
level language to low level language.
22
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Executing/Running Executable Code
23
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Checking Result
24
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
C Program Execution Process
Source Code Compiler Object Code Linker Executable Code User Screen
CPU
Sample.obj Sample.exe
Sample.c
stdio.h
List of ERRORS
Header Files
25
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Introduction to C Language
26
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
What is C Language?
27
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Why do we use C?
28
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Why do we use C?
29
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
History of C Language?
C Language was developed by Dennis Ritchie in the
year of 1972.
Born – September 9, 1941
Profession – Computer Scientist
Place – Bell Labs, US
Known As – Father of C & UNIX
Awards – Turing Award(1983)
National Medal of Technology(1998)
IEEE Medal(1990)
Computer Pioneer Award(1994)
Computer History Museum Fellow(1997) Dennis Ritchie
Harold Pender Award(2003)
Died – October 12, 2011
30
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
History of C Language?
Let’s see the programming languages that were developed before C
language…
31
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Basics of C Programming?
32
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
General Structure of a C Program
/* Documentation */
Pre-Processing Statements
Global Declarations
Main method
33
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
General Structure of a C Program
Documentation /* Documentation */
- It is used to provide brief information Pre-Processing Statements
of the program. Global Declarations
34
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
General Structure of a C Program
Pre-Processing Statements
- It is used to link the header files, /* Documentation */
define the constants, etc... Pre-Processing Statements
Global Declarations
35
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
General Structure of a C Program
Pre-Processing Statements
- Examples /* Documentation */
#include Pre-Processing Statements
#define Global Declarations
#undef
#ifdef
Main method
#ifndef
#if
#else Used defined methods
#elif implementation
#endif
#error
#pragma
36
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
General Structure of a C Program
Global Declaration
- This part is used to declare the /* Documentation */
variables which are common for Pre-Processing Statements
multiple methods. Global Declarations
37
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
General Structure of a C Program
Main method
- main method is the compulsory part for any c /* Documentation */
program. Pre-Processing Statements
- C language is a function oriented programming Global Declarations
language, so every c program must have at least
one function and that must be main. Main method
- Main is a userdefined method which specifies
the starting point of the program execution. Used defined methods
implementation
- Every c program execution starts with main
method and ends with main method itself.
38
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
General Structure of a C Program
Userdefined Methods
- In this section of the program we write the /* Documentation */
actual code for the userdefined methods. Pre-Processing Statements
- Userdefined methods can be implemented Global Declarations
either before or after the method.
Main method
- If it is implemented after the main then it
must be declared either inside or before the
main method. Used defined methods
implementation
- If it is implemented before the main then the
declaration can be ignored.
39
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
General Structure of a C Program - Example
#include<stdio.h>
void main()
{
printf(“Hello World!!!!”);
40
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Rules for Writing C programs
41
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
42
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
What is C Character set?
43
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
What does C Character Set contains?
Alphabets
- C Language supports all alphabets of English. It supports
both UPPERCASE & lowercase letters
Digits
- C Language supports 10 digits to construct numbers. Those
10 digits are 0,1,2,3,4,5,6,7,8,9
Special Symbols
- C supports a rich set of special symbols that include
symbols to perform mathematical operations, condition
checking, white space, back space, etc…
44
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Commonly used Special Symbols with ASCII Values
45
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Note
46
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Keywords in C
47
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
48
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
C Variables
49
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Every variable in c programming language
must be declared in the declaration section
before it is used.
Every variable must have a datatype that
determines the range and type of values be
stored and the size of the memory to be
allocated.
A variable name may contain letters, digits
and underscore symbol. The following are
the rules to specify a variable name...
50
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Variable name should not start with a digit.
Keywords should not be used as variable
names.
A variable name should not contain any
special symbols except underscore(_).
A variable name can be of any length but
compiler considers only the first 31
characters of the variable name.
51
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Declaration Syntax:
datatype variableName;
Examples:
int marks;
char studentName[30];
53
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Rules for Creating Identifiers
54
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Keywords should not be used as identifiers.
There is no limit for the length of an
identifier.
However, the compiler considers the first 31
characters only.
An identifier must be unique in its scope.
55
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Data Types in C
56
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
57
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
58
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
In the c programming language, data types are
classified as follows
59
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Primary data types
The primary data types in the C programming
language are the basic data types.
All the primary data types are already defined in
the system.
Primary data types are also called as Built-In data
types.
The following are the primary data types in c
programming language.
61
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Floating Point data type
62
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Character data type
63
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Operators in C
64
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
C programming language supports a rich set
of operators that are classified as follows.
1.Arithmetic Operators
2.Relational Operators
3.Logical Operators
4.Increment & Decrement Operators
5.Assignment Operators
6.Bitwise Operators
7.Conditional Operator
8.Special Operators
65
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Arithmetic Operators (+, -, *, /, %)
The arithmetic operators are the symbols that are used to perform basic
mathematical operations like addition, subtraction, multiplication, division
and percentage modulo.
66
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Relational Operators
(<, >, <=, >=, ==, !=)
67
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Increment & Decrement Operators (++
& --)
• The increment and decrement operators are called unary operators
because both need only one operand.
• The increment operators adds one to the existing value of the operand
and the decrement operator subtracts one from the existing value of
the operand.
68
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Assignment Operators (=, +=, -=, *=,
/=, %=)
69
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Bitwise Operators (&, |, ^, ~, >>, <<)
70
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Conditional Operator (?:)
71
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
The following are the special operators in c
programming language.
72
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
C Expressions
What is an expression?
An expression is a collection of operators and operands that represents a
specific value.
Expression Types in C
In the C programming language, expressions are divided into THREE
types. They are as follows...
1.Infix Expression
2.Postfix Expression
3.Prefix Expression
73
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
C Constants
In C programming language, a constant is
similar to the variable but the constant hold
only one value during the program execution.
A constant is a named memory location which
holds only one value throughout the program
execution.
Creating constants in C
In a c programming language, constants can be
created using two concepts...
Using the 'const' keyword
Using '#define' preprocessor
74
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Using the 'const' keyword:
const datatype constantName ;
(OR)
const datatype constantName = value ;
Example
const int x = 10 ;
Here, 'x' is a integer constant with fixed
value 10.
75
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Using '#define' preprocessor:
#define CONSTANTNAME value
Example
#define PI 3.14
Here, PI is a constant with value 3.14
76
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
C Input Functions
C programming language provides built-in
functions to perform input operations.
The input operations are used to read user
values (input) from the keyboard.
The c programming language provides the
following built-in input functions.
scanf()
getchar()
getch()
gets()
fscanf()
77
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
scanf() function:
The scanf() function is used to read multiple
data values of different data types from the
keyboard.
The scanf() function is built-in function
defined in a header file called "stdio.h".
When we want to use scanf() function in our
program, we need to include the respective
header file (stdio.h) using #include
statement.
78
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
79
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
80
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
81
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
82
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
C Output Functions
86
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Conditional Statements
Decision-making statements are the
statements that are used to verify a given
condition and decide whether a block of
statements gets executed or not based on
the condition result.
89
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
if-else statement in C:
The if-else statement is used to verify the
given condition and executes only one out of
the two blocks of statements based on the
condition result.
The if-else statement evaluates the
specified condition.
If it is TRUE, it executes a block of
statements (True block).
If the condition is FALSE, it executes another
block of statements (False block).
90
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
If-else statement:
91
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
if-else-if statement (if-else ladder):
Writing a if statement inside else of an if
statement is called if-else-if statement.
92
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Nested if statement:
Writing a if statement inside another if
statement is called nested if statement.
93
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
94
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
'switch' statement in C
95
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
96
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Repetition: Loops
98
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Flowchart
99
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
while is a keyword so it must be used only in
lower case letters.
If the condition contains a variable, it must be
assigned a value before it is used.
The value of the variable used in condition
must be modified according to the requirement
inside the while block.
In a while statement, the condition may be a
direct integer value, a variable or a condition.
A while statement can be an empty statement.
100
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
101
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
'do-while' statement in C
The do-while statement is used to execute a
single statement or block of statements
repeatedly as long as given the condition is
TRUE.
The do-while statement is also known as the
Exit control looping statement.
102
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
103
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
Both do and while are keywords so they must be used
only in lower case letters.
If the condition contains a variable, it must be
assigned a value before it is used.
The value of the variable used in the condition must
be modified according to the requirement inside the
do block.
In a do-while statement, the condition may be a
direct integer value, a variable or a condition.
A do-while statement can be an empty statement.
In do-while, the block of statements is executed at
least once.
104
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
105
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
‘for’ Statement in C
106
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
At first, the for statement executes initialization
followed by condition evaluation.
If the condition is evaluated to TRUE, the single
statement or block of statements of for statement are
executed.
Once the execution gets completed, the modification
statement is executed and again the condition is
evaluated.
If it is TRUE, again the same statements are executed.
The same process is repeated until the condition is
evaluated to FALSE.
Whenever the condition is evaluated to FALSE, the
execution control moves out of the for block.
107
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
108
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
109
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM
for is a keyword so it must be used only in lower
case letters.
Every for statement must be provided with
initialization, condition, and modification (They
can be empty but must be separated with ";")
Ex: for ( ; ; ) or for ( ; condition ; modification ) or for ( ; condition ; )
In for statement, the condition may be a direct
integer value, a variable or a condition.
The for statement can be an empty statement.
110
Dileep Kumar Koda | Asst. Prof. | CSE | RGUKT-SKLM