You are on page 1of 9

3. Draw the basic organization of a computer and explain its components.

(OR) Explain in
detail about basic computer organization with a neat sketch. (OR) Draw a block diagram
of computer and discuss about different components of computer system.

The hardware devices attached to the computer are called peripheral equipment. It
includes all input, output and secondary storage devices.

Central Processing
Unit
Control Unit
Input Devices Output Devices
Arithmetic and
Logical Unit

Memory

Input Devices:

 Input devices allow the user to enter the program and data and send it to the processing
unit.
 The common input devices are keyboard, mouse and scanners
 The keyboard input speed always less than the acceptance speed of memory unit
 But if you try to press the keyboard button continuously then you can hear a beep sound,
because of the speed mismatch

Processor:

 Processor more formally known as the central processing unit (CPU), has the electronic
circuitry that manipulates input data into the information as required. The central
processing unit actually executes computer instructions.
 It is just like the human brain that takes all major decisions, makes all sorts of
calculations and directs different parts of the computer function by activating and
controlling the operation.
 It consists of arithmetic and logic units, control unit and internal memory. The control
unit of the CPU coordinates the action of the entire system.
 Programs provide the CPU, a set of instruction to follow and perform a specific task
between any two components of the computer system, there is a pathway called a bus
which allows for the data transfer between them.

Control Unit:

 Control Unit (CU) coordinates the components of a computer system.


 Control Unit is the brain of the computer system.
 It fetches the code of all of the instructions in the program and directs the operation of the
other units by providing timing and control signals. All computer resources are managed
by the CU.
 It directs the flow of data between the Central Processing Unit (CPU) and the other
devices.

Arithmetic-Logic Unit:

 The arithmetic-logic unit (ALU) performs all arithmetic operations (addition, subtraction,
multiplication, and division) and logic operations.
 Logic operations test various conditions encountered during processing and allow for
different actions to be taken based on the results.

Memory:

 Memory from which the CPU fetches the instructions and data is called main memory. It
is also called as primary memory and is volatile in nature. The content of this memory
will vanish whenever the power is off.
 This holds the instruction and data which come from input devices & processed
information from arithmetic and logic unit.

Output Devices:

 Output devices show the processed data – information – the result of processing. The
devices are normally a monitor and printers.
 These devices are connected to CPU for displaying the instruction and data which are
entered through input devices for user verification.

PROGRAM STRUCTURE OF C

Documentation Section
Preprocessor Section
Definition Section
Global Declaration Section
main ( )
{
Declaration Part
Execution Part
}
Sub Program Section
{
Body of the sub program
}

 Documentation Section:
It consists of set of command lines used to specify the name of the program, the
author of the program and other details etc.
 Comments:
Comments are very helpful in identifying the program features and underlying
logic of the program. The lines with ‘/*’ and ending with ‘*/’ are known as comment
lines. These are not executable, the compiler is ignored anything in between /* and */

 Preprocessor Section:
It is used to link system library files, for defining the macros and for defining the
conditional inclusion.
Example: include <stdio.h>

 Definition Section:
The definition section defines all symbolic constants.
Example: # define pi 3.14

 Global Declaration Section:


The variables that are used in more than one function throughout the program are
called global variable and are declared outside of all the function.
 Main Function:
Every C program must have one main function, which specify the starting of C
program
 Declaration Part:
This part is used to declare all the variables that are used in the executable part of
the program and these are called local variables
 Executable Part:
It contains at least one valid C statement. The execution of a program begins with
opening brace ‘{‘and ends with ‘}’

Rules for writing C program:


 All the statements should be in lower case letters. Upper case letters are only used for
symbolic constants.
 Blank spaces may be inserted between two words. It is not used when declaring variables,
keywords, constants and functions.
 The program statements can write anywhere between the two braces following the
declaration part
 The user can also write one or more statements in one line separating them with
semicolon (;)

Example:

/* To Print "AMET University" on the screen */


#include<stdio.h>
void main ( )
{
printf("AMET University");
}

2. Demonstrate the declaration, initialization, memory allocation of single dimensional


array with suitable syntax and example.

Array:

An array is a group of related data items, which share common name. It is the set of
homogeneous data.

One Dimensional Array:

This type of array is also called as linear array and list array. These arrays are of ladder
type. In the linear array only one subscript is used. It is written either in row or in column form.

Declaration:

Syntax: Data_type array_name [size];

Example: int n [10];

Initialization:

Syntax: Data_type array_name [size] = {list of values};

Example: int n [10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

Memory Allocation:
Always, Contiguous (Or) sequence memory locations are used to store array elements in
memory. Arrays have 0 as the first index not 1. In this example, n [0] If the size of an array is n,
to access the last element, (n - 1) index is used. In this example, n [9]

0 1 2 3 4 5 6 7 8 9
n 1 2 3 4 5 6 7 8 9 10

Example:

#include <stdio.h>
void main ( )
{
int i;
Output:
float n [10], sum = 0.0, avg;
printf ("Enter the numbers of elements: "); Enter the numbers of elements:
for (i = 0; i < 10; i++) 1 2 3 4 5 6 7 8 9 10
{ Sum = 55, Average = 5.5
scanf ("%f", &n [i]);
sum += n [i];
}
avg = sum / n;
printf ("Sum = %f, Average = %f ", sum, avg);
}

1. Examine call by value and call by reference with a suitable example. (OR) Differentiate
call by value and call by reference with an example program. (OR) With suitable example
illustrate “call by value and call by reference” techniques of passing parameters. (OR)
Discuss and differentiate pass by value and pass by reference.

CALL BY VALUE:

When the value is passed directly to the function it is called call by value. In call by value
only a copy of the variable is only passed so any changes made to the variable does not reflects
in the calling function.

Example:

#include <stdio.h>
#include <conio.h>
swap (int, int);

void main ( )
{
int x, y;
printf ("Enter Two numbers:");
scanf ("%d %d", &x, &y);
printf ("Before swapping : x = %d, y = %d", x, y);
swap (x, y);
printf ("After swapping :x = %d, y = %d", a, b);
getch ( );
}
swap (int a, int b)
Output:
{
Enter Two numbers: 12 34
int t;
Before swapping: x = 12, y = 34
t = a;
After swapping: x = 34, y = 12
a = b;
b = t;
}

CALL BY REFERENCE:

When the address of the value is passed to the function it is called call by reference. In
call by reference since the address of the value is passed any changes made to the value reflects
in the calling function.

Example:

#include <stdio.h>
#include <conio.h>
swap (int *, int *);
void main ( )
{
int x, y;
printf ("Enter Two numbers:");
scanf ("%d %d", &x, &y);
printf ("Before swapping : x = %d, y = %d", x, y);
swap (&x, &y);
printf ("After swapping :x = %d, y = %d", a, b);
getch ( );
}
swap (int *a, int *b)
Output:
{
Enter Two numbers: 12 34
int t;
Before swapping: x = 12, y = 34
After swapping: x = 34, y = 12
t = *a;
*a = *b;
*b = t;
}

Storage classes:

A storage class defines the scope (visibility) and life-time of variables and/or functions
within a C Program. They precede the type that they modify. We have four different
storage classes in a C program −

 auto
 register
 static
 extern

The auto Storage Class


The auto storage class is the default storage class for all local variables.
{
int mount;
auto int month;
}
The example above defines two variables with in the same storage class. 'auto' can
only be used within functions, i.e., local variables.

The register Storage Class


The register storage class is used to define local variables that should be stored in a
register instead of RAM. This means that the variable has a maximum size equal to the
register size (usually one word) and can't have the unary '&' operator applied to it (as it
does not have a memory location).
{
register int miles;
}

The register should only be used for variables that require quick access such as
counters. It should also be noted that defining 'register' does not mean that the variable
will be stored in a register. It means that it MIGHT be stored in a register depending on
hardware and implementation restrictions.
The static Storage Class
The static storage class instructs the compiler to keep a local variable in existence
during the life-time of the program instead of creating and destroying it each time it
comes into and goes out of scope. Therefore, making local variables static allows them
to maintain their values between function calls.
The static modifier may also be applied to global variables. When this is done, it
causes that variable's scope to be restricted to the file in which it is declared.
In C programming, when static is used on a global variable, it causes only one copy of
that member to be shared by all the objects of its class.

Live Demo

#include<stdio.h>

void test(); //Function declaration (discussed in next topic)

int main()
{
test();
test();
test();
}

void test()
{
static int a = 0; //a static variable
a = a + 1;
printf("%d\t",a);
}}

When the above code is compiled and executed, it produces the following result −
1 2 3

The extern Storage Class


The extern storage class is used to give a reference of a global variable that is visible
to ALL the program files. When you use 'extern', the variable cannot be initialized
however, it points the variable name at a storage location that has been previously
defined.
When you have multiple files and you define a global variable or function, which will
also be used in other files, then extern will be used in another file to provide the
reference of defined variable or function. Just for understanding, extern is used to
declare a global variable or function in another file.
The extern modifier is most commonly used when there are two or more files sharing
the same global variables or functions as explained below.
First File: main.c
#include <stdio.h>

int count ;
extern void write_extern();

main() {
count = 5;
write_extern();
}

Second File: support.c


#include <stdio.h>

extern int count;

void write_extern(void) {
printf("count is %d\n", count);
}

You might also like