KCS101.201 Theory
KCS101.201 Theory
It has basically four blocks: In addition every algorithm must satisfy following criteria’s:
1. Input- It is used to enter data in computer. Ex. keyboard, mouse etc. 1) Input- Zero or more quantities are externally supplied.
2. Output- It is used to view processed data. Ex. Monitor, printer, speaker 2) Output- At least one quantity is produced.
etc. 3) Definiteness- Each instruction must be clear and unambiguous.
3. Secondry Storage- It is used to store data for future reference. Ex. Hard 4) Finiteness- Algorithm must terminate after finite numbers of steps.
disk, CD, DVD etc. 5) Effectiveness- Each instruction must be sufficiently basic and must
4. Central Processing Unit (CPU)- It is also known as brain of computer. also be feasible.
All processing takes place in it.
It has three blocks. Algorithm can be written in various ways-
a) Control Unit (CU)- It control all components of computer.
1) Natural language
b) Arithmetic & Logic Unit(ALU)- It performs all arithmetic &
2) Flowchart
logical operations on data.
3) Pseudo code
c) Primary Memory- It holds all data and programs under
execution. Ex. RAM & ROM. 3. What is Flowchart? What are various compounds of flowchart?
Ans. Flowcharts are diagrammatic representation of the problem solving
process, in which decision are laid out in logical order.
Central Processing Unit (C.P.U.)
It is called flowchart, since it charts the flow of diagram. (A picture is worth
Control Unit thousand words)
7. What is the use of bitwise operators? Explain any two bitwise operators?
Ans. Bitwise operators are very handy and let us help modify data at bit level.
Bitwise operators are divided into 4 general categories-
1. one’s compliment operator
2. logical bitwise operator
3. shift operators
4. bitwise assignment operators
Goel Institute of Technology & Managemen, Lucknow Goel Institute of Technology & Managemen, Lucknow
B.Tech., Ist Year B.Tech., Ist Year
Programming for Problem Solving (KCS-101/201) Programming for Problem Solving (KCS-101/201)
one’s compliment operator(~)- it is a unary operator that causes bits of its To allocate memory we use library functions in header file <alloc.h>
operand to be inverted. i.e. 0 becomes 1 and 1 becomes 0, 1. malloc()
Ex. int a= 0xc5; 2. calloc()
a= ~a; a= 0000 0000 1100 0101
To free memory we use another function again in <alloc.h>
~a= 1111 1111 0011 1010 1. free()
o/p= a= ff3a Example-
logical bitwise operator- there are three logical bitwise operators # include <stdio.h>
1. bitwise AND (&) # include <alloc.h>
2. bitwise EX-OR (^) void main()
3. bitwise OR (|) { int x,i,n;
printf (“enter no. of elements”);
A B A&B A^ B A|B scanf (“%d”,&n);
0 1 0 0 0 x= (int *) malloc (n*sizeof (int)); //dynamic array of n elements
0 0 0 1 1 for(i=0;i<n;++i)
0 1 0 1 1 scanf(“%d”,x+1);
1 1 1 0 1 printf(“array is\n”);
for(i=0;i<n;++i)
printf (“%d”,*(x+i));
Ex- int a, b;
free(x); // release memory
a= 0x6db7;
}
b= 0xa726;
a & b= 0x2526
9. What is an operating system? Explain various functions performed by it?
a ^ b= 0xca91
a | b= 0xefb7 Ans. An operating system is a system program that manages the resources of
Shift operator- there are two shift operators the computer system. It acts as an interface between man and machine,
1. shift left (<<) moreover other programs rely on facility provided by O.S. to gain access to
2. shift right (>>) computer system resources.
They shift given number by desired no’s of bits to either left or right and Major tasks performed by OS are-
the vacant places are filled by zeroes.
1. Process management
2. Memory management
Example- a= 0x6db7
b= a<<6; 0110 1101 1011 0111 3. Input/ output management
shifted left 4. File management
= 0x6dc0 0110 1101 1100 0000 0’s inserted 5. Security and protection management
6 d c 0
Examples of OS are – DOS, UNIX, LINUX, WINDOWS, and ANDROID etc.
8. What is dynamic memory allocation? Explain malloc and free function?
Ans. Dynamic as name supports is in motion. Dynamic memory allocation is 10. What are different ways of passing parameter to the function? Explain
the ability of a program to allocate and free memory whenever required with example?
during program execution is known as Dynamic memory allocation. Or
Goel Institute of Technology & Managemen, Lucknow Goel Institute of Technology & Managemen, Lucknow
B.Tech., Ist Year B.Tech., Ist Year
Programming for Problem Solving (KCS-101/201) Programming for Problem Solving (KCS-101/201)
Show how arguments are passed by using “call by value” and “call by 12. Difference between DOS, WINDOWS and UNIX OS-
reference” respectively?
Ans. In C there are two ways of passing parameters to a function. DOS WINDOWS UNIX
1. Call by value Command user interface Graphical user interface Command user interface
2. Call by reference (CUI) (GUI) (CUI)
Call by value Call by reference
1. A copy of actual parameters is 1. Address of actual parameters is Single user OS Single user OS Multi user OS
created in function. So actual passed to function. So whatever
data remains unchanged. change is made is reflected in Single program OS Multi program OS Multi programming OS
main program.
2. Using call by value we can 2. Using call by reference multiple Meant for PC with
Outdated, meant for PC
networking capability Portable OS, widely
return at most one value from data can be transferred back.
the function. used has most features.
3. Helps protect the original data 3. Disadvantage of unknowingly
at cost of limited return value. modifying original data but has 13. What is a pointer? Write a C program to swap value of two variables
advantage of multiple return using pointer?
values at same time. Ans. Pointer is a variable that stores the address of other variable and not
Example- Example-
value stored in them. Pointer provides an alternative way to access data
int great (int a, int b) void swap (int &a, int &b)
{ if (a>b) { int c; stored in variable.
return a; c=*a;
else *a=*b; Program to swap variables-
return b; *b=c; # include <stdio.h> void main()
} } void swap (int *a, int *b) {int x,y;
{ int c; scanf (“%d %d”, &x,&y);
11 Explain various types of OS? Differentiate between DOS, WINDOWS and
c= *a; printf (“before swapping
UNIX O.S?
*a= *b; x=%d y=%d \n”, x, y);
Ans. Different types of operating sytem are-
*b= c; swap (&x, &y);
1. Batch OS
} printf (“after swapping x=%d
2. Multiprogramming O.S- it contains multitasking, multiuser and
y=%d \n”, x, y);
multiprocessing O.S.
}
a) Time sharing O.S (multiprogram + multiuser)
b) Real time O.S
14. What is a file? Explain different file opening under in C?
c) Combination O.S
Ans. File also known as data file is collection of data/ program stored on
3. Distributed O.S
secondary storage device such as Hard disk for future use/ backup.
Different modes in which file are opened in read, write and append.
Goel Institute of Technology & Managemen, Lucknow Goel Institute of Technology & Managemen, Lucknow
B.Tech., Ist Year B.Tech., Ist Year
Programming for Problem Solving (KCS-101/201) Programming for Problem Solving (KCS-101/201)
S.No. Mode Description A node may contain heterogeneous data and a node may be present
1. “r” Read: Open existing file for reading. Error if no file is found. anywhere in computer memory and not necessary in consecutive
2. “w” Write: Open new file for writing. it overwrite existing file if any memory location.
3. “a” Append: Open existing file for writing at end. It creates new file nd
First node contains address of 2 node and so on.
if no file is found.
4. “r+” Read+: Open existing file for read and write. Creates new file if Since each node is connected by links/address they are called linked
no existing file. list. They have advantage of inserting and deleting data very easily.
5. “w+” Write+: Open new file for read and write overwrite existing file. Types of linked list-
6. “a+” Append+: Open existing file for both read and append. If there a. Single linked list
is no file new file is created. b. Doubly linked list
c. Circular linked list.
Example Example
struct node union node
{ char c; { char c;
int i; int i;
float f; float f;
}; };
void main()
{ int a,b;
scanf (“%d%d”,&a,&b);
sum(a,b);
}
Passing arguments in this fashion is also known as call by name.