Professional Documents
Culture Documents
(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:
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
Example:
Array:
An array is a group of related data items, which share common name. It is the set of
homogeneous data.
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:
Initialization:
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 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>
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
int count ;
extern void write_extern();
main() {
count = 5;
write_extern();
}
void write_extern(void) {
printf("count is %d\n", count);
}