UNIT-01 Computer Fundamentals
UNIT-01 Computer Fundamentals
Pre-requisite keywords:
• Program:A program can be defined as a collection
of instructions written to perform any user`s
defined task in computer.
• Data:Any raw facts
• Information: Collection of data that has some
meaning (Meaningful Data)
• Hardware:Computer hardware is a collective term
used to describe any of the physical components
of an analog or digital computer.
Introduction to components of a computer system: Memory,
Processor, I/O Devices
Pre-requisite keywords:
• Software:Software commands the hardware what to do & how
to do it. Together, the hardware & software form the computer
system. This software is further classified as system software &
application software.
• System Software:System software are a set of programs,
responsible for running the computer, controlling various
operations of computer systems and management of computer
resources. They act as an interface between the hardware of the
computer & the application software. E.g.: Operating System.
• Application software: Application Software is a set of programs
designed to solve a particular problem for users. It allows the
end user to do something besides simply running the hardware.
E.g.: Web Browser, Gaming Software, etc.
Introduction to components of a computer system: Memory,
Processor, I/O Devices
Introduction to computer:
Right from its inception, to the present day, all computer system
(irrespective of their shape & size) perform the following 5 basic
operations. It converts the raw input data into information, which is
useful to the users.
Introduction to components of a computer system: Memory,
Processor, I/O Devices
Components of computer:
Input: It is the process of entering data & instructions
to the computer system.
Storing: The data & instructions are stored for either
initial or additional processing, as & when required.
Processing: It requires performing arithmetic or logical
operation on the saved data to convert it into useful
information.
Output: It is the process of producing the output data
to the end user.
Controlling: The above operations have to be directed
in a particular sequence to be completed.
Introduction to components of a computer system: Memory,
Processor, I/O Devices
Input Unit:
Input device: The input device is the means through
which data and instructions enter in a computer.
• Keyboard
• Mouse
• Microphone
• Joysticks
• Scanner
• Barcode Reader
• Camera
• Compact Disc (CD),etc.
Introduction to components of a computer system: Memory,
Processor, I/O Devices
Memory/Storage Unit: The storage unit is designed to
save the initial data, the intermediate result & the final
result.
They are of two types:
• Primary storage: The primary storage, also called as the
main memory, holds the data when the computer is
currently on. It is volatile in nature. Ex: RAM
Control Unit:
This unit controls the operations of all parts of the
computer but does not carry out any actual data
processing. It is responsible for the transfer of
data and instructions among other units of the
computer. It manages and coordinates all the
units of the system. It also communicates with
Input/Output devices for transfer of data or
results from the storage units.
Introduction to components of a computer system: Memory,
Processor, I/O Devices
OUTPUT
INTEREST
END
SOME EXAMPLES OF FLOW CHART AND
ALGORITHM
Example: Determine and Output Whether Number N is
Even or Odd
PREPROCESSOR
Modified source
program
COMPILER
Target
assembly
language
ASSEMBLER
Relocatable
machine
code
Library files
Linker/Loader relocatable
object files
Target machine
code
C PROGRAMMING
Before we study the basic building blocks of the C
programming language, let us look at a bare
minimum C program structure so that we can take it
as a reference in the upcoming chapters.
Hello World Example
A “C” program basically consists of the following
parts − #include <stdio.h>
•Preprocessor Commands int main()
•Functions {
/* my first program in C */
•Variables
printf("Hello, World! \n");
•Statements & Expressions return 0;
•Comments }
C PROGRAMMING (BASIC SYNTAX)
Basic Syntax:
Tokens in C
A C program consists of various tokens and a token is either a
keyword, an identifier, a constant, a string literal, Operators and
special symbols. For example, the following C statement consists of
five tokens −
Comments:
Comments are like helping text in your C program and they are
ignored by the compiler. They start with /* and terminate with the
characters */ as shown below −
/* my first program in C */
C PROGRAMMING (BASIC SYNTAX)
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.
Thus, Sum and sum are two different identifiers in C. Here are
some examples of valid identifiers −
Area, sum, stu_add, _add, sum_1, sum1;
Invalid identifiers:
12sum, #asdj, sum@123
C PROGRAMMING (BASIC SYNTAX)
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.
C PROGRAMMING (BASIC SYNTAX)
Whitespace:
A line containing only whitespace, possibly with a comment, is
known as a blank line, and a C compiler totally ignores it.
int a, float b;
x = 70.0/3.0;
printf("value of x : %f \n", x);
return 0;
}
C PROGRAMMING (ERRORS)
Errors:
Error is an illegal operation performed by the user which results in
abnormal working of the program.
Types of Error:
There are 5 types of error in C:
•Syntax Errors
•Runtime Errors
•Logical Errors
•Linked Errors
•Semantic Errors
C PROGRAMMING (ERRORS)
Types of Error:
•Syntax Errors
These are also referred to as compile-time errors. These errors
have occurred when the rule of C writing techniques or syntaxes
has been broken.
INCORRECT CORRECT
C PROGRAMMING (ERRORS)
Types of Error:
•Runtime Error
This type of error occurs while the program is running.
Because this is not a compilation error, the compilation will
be completed successfully.
C PROGRAMMING (ERRORS)
Types of Error:
•Logical Error
Logical errors are those errors in which we think that our code is correct,
the code compiles without any error and gives no error while it is running,
but the output we get is different from the output we expected.
INCORRECT
C PROGRAMMING (ERRORS)
Types of Error:
•Semantic Error
Errors that occur because the compiler is unable to
understand the written code are called Semantic Errors.
#include <stdio.h>
void main()
{
int a, b, c;
a * b = c; // generate a semantic error
}
void Main()
{
int var = 10;
printf("%d", var);
}
Output: 1.400000
C PROGRAMMING
Types of Type casting/Type Conversion:
Types of typecasting in C
•Implicit Conversion :
Implicit conversions do not require any operator for converted.
They are automatically performed when a value is copied to a
compatible type in the program.
•Explicit Conversion:
In C language, Many conversions, especially those that imply a
different interpretation of the value, require an explicit conversion.
C PROGRAMMING
Types of Type casting/Type Conversion:
Ex: Implicit Ex: Explicit
#include<stdio.h> #include<stdio.h>
#include<conio.h> #include<conio.h>
void main() void main()
{ {
int i=20; double p; int i=20, float p;
clrscr(); clrscr();
p=i; // Implicit Conversion p=(float)i; // Explicit Conversion
printf(“implicit value is %d”, p); printf(“Explicit value is %f”, p);
getch(); getch();
} }