Unit 1
Unit 1
Data entered into computer is sent to RAM, from where it is then sent to
ALU, where rest of data processing takes place. All types of processing,
such as comparisons, decision-making and processing of non-numeric
information takes place here and once again data is moved to RAM.
Control Unit
Memory Unit
This is unit in which data and instructions given to computer as well as
results given by computer are stored. Unit of memory is "Byte".
1 Byte = 8 Bits
What is a Computer?
Functions of Computers
1 History of Computers
The history of the computer dates back to several years.
There are five prominent generations of computers. Each
generation has witnessed several technological advances
which change the functionality of the computers.
7 Output Devices
Output devices help to display output to user
8 Computer Memory
Computer memory refers to storage area where data is
stored. It is of two types Primary Memory & Secondary
Memory.
10 Programming Languages
The languages that are used to write a program or set of
instructions are called "Programming languages".
Programming languages are broadly categorized into
three types - Machine level language, Assembly level
language, High-level language.
11 Representation of Data/Information
Computer does not understand human language. Any
data, viz., letters, symbols, pictures, audio, videos, etc.,
fed to computer should be converted to machine language
first. Computers represent that data into different forms.
13 Applications of IECT
IECT stands for Information Electronics and
Communication Technology.
Producing output
The processed information and other details are communicated to the
outside world through output devices like monitor, printer, etc.
Operating System
Operating system is a software that controls system’s hardware and
interacts with user and application software.
In short, an operating system is computer’s chief control program.
Functions of Operating System
The operating system performs the following functions −
It offers a user interface.
Loads program into computer’s memory.
Coordinates how program works with hardware and other software.
Manages how information is stored and retrieved from the disk.
Saves contents of file on to disk.
Reads contents of file from disk to memory.
Sends document to the printer and activates the printer.
Provides resources that copy or move data from one document to
another, or from one program to another.
Allocates RAM among the running programs.
Recognizes keystrokes or mouse clicks and displayes characters or
graphics on the screen.
3 User Interface
While working with a computer, we use a set of items on
screen called "user interface". In simple terms, it acts as
an interface between user and software application or
program
4 Running an Application
The operating system offers an interface between
programs and user, as well as programs and other
computer resources such as memory, printer and other
programs.
8 Types of Files
There are five types of files such as Ordinary files,
Directory files, Device files, FIFO files
It is easy to understand.
Algorithm is a step-wise representation of a solution to a given problem.
In Algorithm the problem is broken down into smaller pieces or steps
hence, it is easier for the programmer to convert it into an actual
program.
Disadvantages of Algorithms:
Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values num1 and num2.
Step 4: Add num1 and num2 and assign the result to sum.
sum←num1+num2
Step 5: Display sum
Step 6: Stop
Algorithm 2: Find the largest number among three numbers
Step 1: Start
Step 2: Declare variables a,b and c.
Step 3: Read variables a,b and c.
Step 4: If a > b
If a > c
Display a is the largest number.
Else
Display c is the largest number.
Else
If b > c
Display b is the largest number.
Else
Display c is the greatest number.
Step 5: Stop
Representation of algorithm
FLOW CHART
Diagrammatic representation of an algorithm is called flow chart.
Symbols used in flowchart are mentioned below –
Terminal start/stop/begin/end
Oval
Parallelogram
Rectangle
Diamon
Name Symbol Purpose
Circle
Arrows
Pentagon
Hexagon
Printout
Example
Given below is the flowchart for finding an average of three numbers −
Data Types in C
A data type specifies the type of data that a variable can store such as
integer, floating, character, etc.
There are the following data types in C language.
The memory size of the basic data types may change according to 32 or
64-bit operating system.
float 4 byte
double 8 byte
1. int main()
2. {
3. int a=10;
4. int A=20;
5. printf("Value of a is : %d",a);
6. printf("\nValue of A is :%d",A);
7. return 0;
8. }
Output
Value of a is : 10
Value of A is :20
HTML Tutorial
Comments in C
1. #include<stdio.h>
2. int main(){
3. //printing information
4. printf("Hello C");
5. return 0;
6. }
Multi-Line comments are represented by slash asterisk \* ... *\. It can occupy
many lines of code, but it can't be nested. Syntax:
1. /*
2. code
3. to be commented
4. */
5.
6. #include<stdio.h>
7. int main(){
8. /*printing information
9. Multi-Line Comment*/
10. printf("Hello C");
11. return 0;
12. }
Programming Errors in C
Errors are the problems or the faults that occur in the program, which
makes the behavior of the program abnormal, and experienced developers
can also make these faults. Programming errors are also known as the bugs
or faults, and the process of removing these bugs is known as debugging.
o Syntax error
o Run-time error
o Linker error
o Logical error
o Semantic error
Syntax error
Syntax errors are also known as the compilation errors as they occurred at the
compilation time, or we can say that the syntax errors are thrown by the compilers.
These errors are mainly occurred due to the mistakes while typing or do not follow
the syntax of the specified programming language. These mistakes are generally
made by beginners only because they are new to the language. These errors can be
easily debugged or corrected.
For example:
1. #include <stdio.h>
2. int main()
3. {
4. a = 10;
5. printf("The value of a is : %d", a);
6. return 0;
7. }
Logical error
The logical error is an error that leads to an undesired output. These errors
produce the incorrect output, but they are error-free, known as logical
errors. These types of mistakes are mainly done by beginners. The
occurrence of these errors mainly depends upon the logical thinking of the
developer. If the programmers sound logically good, then there will be
fewer chances of these errors.
1. #include <stdio.h>
2. int main()
3. {
4. int sum=0; // variable initialization
5. int k=1;
6. for(int i=1;i<=10;i++); // logical error, as we put the semicolon after loop
7. {
8. sum=sum+k;
9. k++;
10. }
11. printf("The value of sum is %d", sum);
12. return 0;
13. }
Data Types in C Language
Data type defines the type of data being used.
For example, you may want to use a number like 1, 2, 100, or a decimal
points number like 99.95, 10.5, or a text, like "Studytonight", all these values
are handled differently by the C compiler, hence, we use data types to define
the type of data used in any program.
Data Types in C
Type Example
Enumeration enums
Type Example
Character (char):
Integer (int):
Floating-point (float):
Double (double):
1. We use the keyword double for the double data type.
2. The double data type is used to store decimal numbers.
3. It occupies 8 bytes of memory and ranges from 1e-37 to 1e+37.
4. Here is how we use it in code,
double a = 10.09;
double b = -67.9;
5. The double data type has more precision than float so double gives more
accurate results as compared to float.
6. We can perform addition, subtraction, division, and multiplication
operations on double data type.
Void (void):
Each data type has a size defined in bits/bytes and has a range for the values
that these data types can hold.
3. float is 4 bytes
4. double is 8 bytes
5. void is 0 bytes
The void data type means nothing, hence it doesn't have a size.
……………………………………………………………………………………
Variables in C (with Examples)
A variable is like a container (storage space) with a name in which you
can store data.
When you create a variable in C programming a new memory space gets
assigned to the variable.
While creating a new variable you have to provide it a name and specify
datatype for the variable.
Once you have created the variable, you cannot change its datatype.
When we create a variable in a C program, the C compiler allocates a
storage space, depending upon the data type of the variable(8
bits for char, 16/32 bits for int, etc.)
Then that storage space is given a name which is the variable name.
Here is how you can create or declare a new variable in the C language,
data_type var_name;
Where, data_type is a valid data type (along with datatype modifiers, if
required) and var_name is the name of the variable.
For example,
int marks;
Here, marks is the name of the variable, and it can store values of int type.