Exam Question
Exam Question
Ans:- A flowchart is a diagram that uses symbols and arrows to show the steps, sequences, and decisions in
a process or workflow. Flowcharts are used in computer programming to show the flow of program.
Q1 b) Explain each components of computer with neat block diagram. Also differentiate primary and
secondary memory.
Ans:-
Input
All the data received by the computer goes through the input unit. The input unit comprises
different devices like a mouse, keyboard, scanner, etc. In other words, each of these devices acts
as a mediator between the users and the computer.
The data that is to be processed is put through the input unit. The computer accepts the raw data
in binary form. It then processes the data and produces the desired output.
CU – Control Unit
The control unit as the name suggests is the controller of all the activities/tasks and operations. All
this is performed inside the computer.
The memory unit sends a set of instructions to the control unit. Then the control unit in turn
converts those instructions. After that these instructions are converted to control signals.
These control signals help in prioritizing and scheduling activities. Thus, the control unit
coordinates the tasks inside the computer in sync with the input and output units.
Memory Unit
All the data that has to be processed or has been processed is stored in the memory unit. The
memory unit acts as a hub of all the data. It transmits it to the required part of the computer
whenever necessary.
The memory unit works in sync with the CPU. This helps in faster accessing and processing of the
data. Thus, making tasks easier and quicker.
RAM stands for Random Access Memory. It is an example of primary memory. This memory is
directly accessible by the CPU. It is used for reading and writing purposes. For data to be
processed, it has to be first transferred to the RAM and then to the CPU.
Secondary Memory
As explained above, the primary memory stores temporary data. Thus it cannot be accessed in
the future. For permanent storage purposes, secondary memory is used. It is also called
permanent memory or auxiliary memory. The hard disk is an example of secondary memory. Even
in a power failure data does not get erased easily.
Output
There is nothing to be amazed by what the output unit is used for. All the information sent to the
computer once processed is received by the user through the output unit. Devices like printers,
monitors, projectors, etc. all come under the output unit.
The output unit displays the data either in the form of a soft copy or a hard copy. The printer is for
the hard copy. The monitor is for the display. The output unit accepts the data in binary form from
the computer. It then converts it into a readable form for the user.
Primary memory Secondary memory
Primary memory is volatile, which means it is Since it is non-volatile, data can be retained
wiped out when the computer is turned off. in case of a power failure.
Primary memory Secondary memory
The memory devices used for primary The secondary memory devices are
memory are semiconductor memories. magnetic and optical memories.
It can hold data/information currently being It can hold data/information that are not
used by the processing unit. currently being used by the processing unit.
Examples: RAM, ROM, Cache memory, Examples: Hard Disk, Floppy Disk, Magnetic
PROM, EPROM, Registers, etc. Tapes, etc.
ii) We use the ternary operator in C to run one code when the condition is true and another code
when the condition is false.
In this program b=(a==10)?5:10; is ternary operator which means if condition is true then b=5 else
b=10
So here the condition is true as the value of a is 10 so the value of b becomes 5.
Step 2:-while loop will terminate when the value of n become less than 0.
finally the loop will terminate and we will see that it had displayed the following.
p+=n+=m mean p=p+n and n=n+m so the values are always calculate from right to left.
Hence n=0+9 so n=9 now p=0+n so p=9
So here the values are m=9,p=9,n=9
v) a=15 ,b=13,c=16
x=15 – 1+c * 0 %2 + 13 /4
x= 14+ 0 +3
x= 17
so the output will be 17 0 ( as y have no value but displayed first from right in printf)
3 a) Explain unary, binary and ternary operators available in c. Also describe the role of precedence and
associativity with an example.
-- (decrement operator)
Example
a = 5;
++a;
--a;
Binary Operator
Two operands are required to perform calculation.
+, -, *, % etc.
Example
a = 5;
b = 15;
a + b;
a - b;
Ternary Operator
Three operands are required to perform calculation.
Example
(expression 1)? (expression 2): (expression 3);
a > b?printf("a"):printf("b");
Operator
Precedence Description Associativity
1 Left-to-Right
. Dot Operator
* Dereference Operator
12 || Logical OR Left-to-Right
14 = Assignment Right-to-Left
*= , /= Multiplication, division
Operator
Precedence Description Associativity
assignment
User Defined The user-defined data types are defined by the user structure,
Data Types himself. union, enum
Keywords are predefined, reserved words used in programming that have special
meanings to the compiler. Keywords are part of the syntax and they cannot be used as
an identifier.
C Keywords
auto double int struct
do if static while
Identifier refers to name given to entities such as variables, functions, structures etc.
Identifiers must be unique. They are created to give a unique name to an entity to
identify it during the execution of the program. For example:
int money;
double accountBalance;
We define a constant in C language using the const keyword. Also known as a const
type qualifier, the const keyword is placed at the start of the variable declaration to
declare that variable as a constant.
Syntax to Define Constant
const data_type var_name = value;