1st Unit (1) PPS
1st Unit (1) PPS
1.1 Memory: Memory is the best essential components of a computer because computer
can‘t perform the simple tasks. Computer memory is of two basic types – Primary and
Secondary memory. Random Access Memory (RAM) is volatile memory and Read Only
Memory (ROM) is non-volatile memory.
Note:
Cache Memory: Cache memory is a small, fast memory unit located close to the CPU. It
stores frequently used data and instructions that have been recently accessed from the
main memory. Cache memory is designed to minimize the time it takes to access data by
providing the CPU with quick access to frequently used data.
1.4 Storage: This component is used to store the data or the work done by you. These
storage devices communicate in both directions with CPU. You can send the data to these
devices or the CPU can receive the data as well. It is also known as auxiliary
storage, secondary storage and external storage which is used to store a large amount of
data at lesser cost than primary storage. Secondary storage does not lose the data when
there is no power supply. Secondary storage is also known as non-volatile (means
permanent).
Some of the storage devices are: Hard disk drive, Floppy Disk Drive, DVD/CD, External
USB drive, Pen-drives, Memory cards
(1) Real-time Operating System: A real time operating system is the one which services on-
line external processes having strict timing response. It is a multitasking operating system
that wants at executing real-time applications. The main object of real-time operating
system is rapid response and reliability. Windows CE, OS-9, Symbian and LynxOS are
some of the commonly known real-time operating systems.
e.g. satellite control system, weather forecasting, patient monitoring system.
Single user, single tasking operating system only has to deal with one person at a time,
running one user application at a time.
An example of this kind of operating system would be found on an old mobile phone. There
can only be one user using the mobile and that person is only using one of its applications
at a time.
Single user, multi-tasking operating system would be found on a personal computer. The
operating system is designed mainly with a single user in mind, but it can deal with many
applications running at the same time.
For example, you might be writing an essay, while searching the internet and downloading
a video file.
e.g. Windows, Linux, Mac OS are examples of single-user operating systems.
3. Assembler:
The software that converts assembly language programs to an object file or machine
language program is called Assembler. Each line in assembly language translates to a single
machine code instruction. It also allocates the area of main storage as well as indicates
invalid source language instructions. Assemblers are generally simpler to write than
compilers for high level languages, and have been available since the 1950s.
4. Compiler:
A compiler is a computer program (or set of programs) that translates source
program written in a programming language (such as C, C++) into another target language
(such as machine code, object code) that a CPU can execute. The most common reason for
wanting to transform source code is to create an executable program. The name
"compiler" is generally used for programs that translate source code from a high-level
programming language to a lower level language (e.g., assembly language or machine
code).
5. Interpreter:
An interpreter is a program which translates statements of a program into machine code.
It translates only one statement of the program at a time. It reads only one statement of
program, translates it and executes it. Then it reads the next statement of the program
again translates it and executes it. In this way it proceeds further till all the statements are
translated and executed. On the other hand, a compiler goes through the entire program
and then translates the entire program into machine codes. A compiler is 5 to 25 times
faster than an interpreter.
By the compiler, the machine codes are saved permanently for future reference. On the
other hand, the machine codes produced by interpreter are not saved. An interpreter is a
small program as compared to compiler. It occupies less memory space, so it can be used in
a smaller system which has limited memory space.
6. Loader:
Loader is a program that loads machine codes of a program into the system
memory. A loader is the part of an Operating System that is responsible for loading
programs. It is one of the important stages in the process of starting a program. Because it
loads programs into memory and prepares them for execution. Loading a program
involves reading the contents of executable file into memory. Once loading is complete, the
operating system starts the program by passing control to the loaded program code. All
operating systems that support program loading have loaders. In many operating systems
the loader is permanently resident in memory.
7. Linker:
Linking is the final stage of compilation. It takes one or more object files or libraries as
input and combines them to produce a single (usually executable) file. In high level
languages, some built in header files or libraries are stored. These libraries are predefined
and these contain basic functions which are important for executing the program. These
functions are linked to the libraries by a program called Linker. If linker does not find a
library of a function then it informs to compiler and then compiler generates an error. Not
built in libraries, it also links the user defined functions to the user defined libraries.
Usually a longer program is divided into smaller subprograms called modules. And these
modules must be combined to execute the program. The process of combining the modules
is done by the linker.
Compiler Interpreter
In case of no error, the Compiler converts Execution of source statements one by one.
the whole source code to Machine Code.
The compiler saves the Machine Language The Interpreter does not save the Machine
in form of Machine Code on disks. Language.
Compiled codes run faster than Interpreted codes run slower than
Interpreter. Compiler.
The compiler generates an output in the The interpreter does not generate any
form of (.exe). output.
Any change in the source program after the Any change in the source program during
compilation requires recompiling the entire the translation does not require
code. retranslation of the entire code.
Errors are displayed in Compiler after Errors are displayed in every single line.
Compiling together at the current time.
It does not require source code for later It requires source code for later execution.
execution.
Object code is permanently saved for No object code is saved for future use.
future use.
C, C++, C#, etc are compiler-based. Python, Perl, MATLAB, etc are interpreter-
based.
Characteristic of Algorithm:
1. Input: it may accept 0 or more inputs.
2. Output: It should provide at least 1 output.
3. Definiteness: Each instruction must be clear, well defined and precise. There should be no
ambiguity.
4. Finiteness: It should be a sequence of finite instructions.
5. Effectiveness: This means that operations must be simple and carried out in finite time.
Algo2. Write an algorithm to find the factorial of a given positive integer number.
Step1. Start
Step2. Read the number, say x
Step3. Set fact=1
Step4. Repeat step 5 and 6 until (x==1)
Step5. fact=fact * x
Step6. x=x-1
Step7. print the final value of fact
Step8. Stop
4. Flow lines:
It show the actions order in an algorithm.
Example2. Draw flowchart to find the largest among three different numbers entered by
user.
Try yourself………
10. Pseudocode:
It is a simple way of writing programming code in English. Pseudocode is not actual
programming language. It uses short statement to write code for programs before you
actually create it in a specific language. Once you know what the program is about and
how it will function, then you can use pseudocode to create statements to achieve the
required results for your program.
Examples:
X=n
Y=1
while X !=1 do
Y=Y*X
X=X-1
return Y
START
DISPLAY "Enter the Number - "
READ number
IF number MOD 2 == 0 THEN
DISPLAY "Number is Even"
ELSE
DISPLAY "Number is Odd"
END IF
STOP
Example:
#include<stdio.h>
#include<math.h>
3. Definition
Preprocessors are the programs that process our source code before the process of
compilation. There are multiple steps which are involved in the writing and execution of
the program. Preprocessor directives start with the ‗#‘ symbol. The #define preprocessor is
used to create a constant throughout the program. Whenever this name is encountered by
the compiler, it is replaced by the value of defined code.
Example:
#define row 3
4. Global Declaration
The global declaration section contains global variables, function declaration. Variables
and functions which are declared in this scope can be used anywhere in the program.
Example:
int num = 18;
5. Main() Function
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. 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()
or
int main()
6. Sub Programs
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 main or outside
the main() function. These are specified as per the requirements of the programmer.
Example:
int sum(int x, int y)
{
return (x+y);
}
/*
description: program to find sum. */
#define X 20 // Definition
Output
Sum: 75
Characteristics of C:
Structured programming language
General purpose programming language
No right formats
High level language and also called middle level language
Platform dependent
13. Errors in C
13.1 Syntax errors –
Errors that occur when you break the rules of writing C syntax are known as syntax
errors. This compiler error indicates something that must be fixed before the code can be
compiled. All these errors are detected by compiler and thus are known as
compile-time errors.
Object code is the output of a compiler after it processes the source code. The object code is
usually a machine code, also called a machine language, which can be understood directly
by a specific type of CPU (central processing unit).
Executable code is the output of a linker after it processes the object code. A machine code
file can be immediately executable (i.e., runnable as a program), or it might
require linking with other object code files (e.g. libraries) to produce a complete executable
program.
Semicolons
In a C program, the semicolon is a statement terminator. That is, each individual statement
must be ended with a semicolon. It indicates the end of one logical entity.
Identifiers
A C identifier is a name used to identify a variable, function, or any other user-defined
item. An identifier starts with a letter A to Z, a to z, or an underscore ‗_‘ followed by zero
or more letters, underscores, and digits (0 to 9).
C does not allow punctuation characters such as @, $, and % within identifiers. C is a case-
sensitive programming language.
Keywords
The following list shows the reserved words in C. These reserved words may not be used as
constants or variables or any other identifier names.
e.g.- int, char, float, switch, break, union, void, auto, while, double, do, case etc.
Whitespace in C
A line containing only whitespace, possibly with a comment, is known as a blank line, and a
C compiler totally ignores it.
Whitespace is the term used in C to describe blanks, tabs, newline characters and
comments.
Therefore, in the following statement −
int age;
there must be at least one whitespace character (usually a space) between int and age for
the compiler to be able to distinguish them.
C language provides the functions getc(), getchar(), putc(), putchar(), scanf(), printf() for
character input- output and gets(), puts() for string based input-output. The scanf() and
printf() functions accepts ―a format specifier string‖ and ―a list of variables‖. The format
specifier string is a character string which specifies the data type of each variable to be
input or output.
In C, keyboard is considered as standard input device and monitor is standard output
device.
Example of Automatic:
#include<stdio.h>
void main()
{
auto int i;
printf(―%d‖,i);
}
O/P: -28762 (garbage value)
Example of Register:
#include<stdio.h>
#include<conio.h>
void main()
{ clrscr(); Output: Hello
register int k; Hello
for(k=0;k<5;k++) Hello
printf(―\n Hello‖); Hello
getch(); Hello
}
Example of static:
#include<stdio.h>
void main()
{ clrscr(); Output: 1
static int count;
count=count+1; // default value of count =0
printf(― %d‖, count);
}
Example of extern:
#include<stdio.h>
increment();
decrement();
extern int i=5;
void main()
{
printf(―%d\t‖,i); // i=5
increment ();
decrement ();
printf(―%d‖,i);
}
increment ()
{ i=i+1;
printf(―%d\t‖,i); // i=6
}
decrement ()
{ i=i-1;
printf(―%d\t‖,i); // i=5 Output: 5 6
5 5
}