Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
13 views8 pages

KCS101.201 Theory

The document provides an overview of programming concepts for B.Tech. first-year students, covering topics such as block diagrams of computers, algorithms, flowcharts, data types in C, storage classes, and memory management. It explains various programming constructs, including dynamic memory allocation, bitwise operators, and different operating systems. Additionally, it discusses parameter passing methods, pointers, file handling, and data structures like stacks and queues.

Uploaded by

piyush123sriva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views8 pages

KCS101.201 Theory

The document provides an overview of programming concepts for B.Tech. first-year students, covering topics such as block diagrams of computers, algorithms, flowcharts, data types in C, storage classes, and memory management. It explains various programming constructs, including dynamic memory allocation, bitwise operators, and different operating systems. Additionally, it discusses parameter passing methods, pointers, file handling, and data structures like stacks and queues.

Uploaded by

piyush123sriva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

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)
1) Draw and explain block diagram of Computer? 2. What is Algorithm?
Ans. Block diagram of computer defines the working of digital computer. Ans. An Algorithm is a finite set of instructions which if followed
It is also known as Von-Neuman architecture. accomplishes a particular task.

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)

Various components of flowchart-


Arithmetic Logic
1) Start/ stop box- used for beginning and end of flowchart.
INPUT Unit OUTPUT
(ALU) 2) Process box- used for process and action.
3) Input/ output box- used to indicate input and output of
Devices program.
outside Data
Main Memory
CPU are Lines 4) Decision box- used when we have to choose between
called Control two different paths.
Peripheral Secondary Lines
devices 5) Flow lines - To show flow of logic in flowchart.
Memory 6) Connectors- Used to break and join a long flowchart.
A
A
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)
SNo Storage class Location Initial Scope Life
4. What are various data types in C? What are modifiers? What are format value
specifiers (conversion character)? 1. Automatic storage Main Junk Local Till control remain
Ans. C has four basic data types. They are used for classification of data for Class (auto) memory value variable within function
proper use. 2. Register storage CPU Junk Local Till control remain
SNo Data Type Keyword Size Specifier Remarks
Class (register) register value variable within function
(Bytes)
1 Integer int 2 %d Used to read
Static storage Class Main Zero Local As long as program
integers 3.
(static) memory variable is under execution
2 Character char 1 %c Used to read
4. External storage Main Zero Global As long as program
Characters
Class (external) memory variable is under execution
3 Floating float 4 %f To read single
precision number
4 Double double 8 %f To read double
6. What is precedence and associativity? Explain with help of an example.
precision number
Ans. In real life we follow BODMAS rule to solve arithmetic expressions. In
computer science they are solved with the help of precedence and
Qualifiers – in addition there are four qualifiers which are used to modify associativity rules.
the range of the basic data types. Precedence- is order of evaluation. It defines which operator has higher
I) short II) long III) signed IV) unsigned. priority and will be evaluated first.
Example- * / % has higher precedence
5. Discuss various storage classes in C? + - has lower precedence
Ans. In C there are 2 ways to categorize variables-
I. by data type 2+3*4 first multiplication takes place
II. by storage class. = 2+12 now addition takes place
Data type refers to information represented by variable, while storage class = 14 Ans.
refers to the permanence of a variable, its scope within the program and also Associativity- is direction of evaluation. It comes into picture when two
its default value. operator of same precedence occur side by side.
It can easily be summarized in chart below Example- all arithmetic operators associativity is L R (left to right)
= 2*3/4 since * is on left and will be evaluated first
= 6/4 now division take place
= 1 Ans.
However we can use parenthesis to change natural precedence of operators.

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.

15. Write short notes on- C) Stack & Queue-


Ans. Stacks and Queues are linear data structures and has various application
a) Structured programming- in computer science.
Ans. Structured programming is a programming paradigm aimed at improving
Stacks: (LIFO list) Last In First Out
the clarity, quality and development time of a computer program by making
extensive use of functions, and control statements like branching and looping, in Stack is also known as LIFO list has one end known as Top.
contrast to using simple test and jumps such as goto statement.
It aimed at to create block of code with single entry and single exit with no way Operations on stack- F Top
of jumping in between the block. Push- Add new element at top E
Pop- Delete top element D
Entry Peep- Look at top element C
Block 1 B
Stack
A
Exit
Block 2 STACK
Queue: (FIFO list) First In First Out
b) Linked list-
Also known as FIFO list has two ends Front & Rear. Elements are added at
Ans. Linked list is a linear data structure which is aimed to overcome all the
Rear and deleted from Front.
problems being faced by using arrays.
In linked list data is stored in notes. Operations on queue-
Example: node Insert- Add an element at rear Front A B C D Rear
struct node
{ int data; data link Delete- Remove an element from front. Queue
struct node*link;
}; D) Increment and Decrement Operators-
Ans. Increment (++) & Decrement (--) operators are unary operators and used
to increase and decrease the value of operand by 1.
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)
 Increment operators are used in two different ways F) Memory Hierarchy-
- Pre increment ++a; increment and then use Ans. It is arrangement of various memory units in computer system for
- Post increment a++; first use and then increment proper functioning and at same time keeping cost low. It is striking balance
speed and cost.
 Similarly decrement operators are used in two different ways
- Pre decrement --a; decrement and then use Memory Hierarchy
- Post decrement a--; first use and then decrement
CPU
Difference between pre and post operators
Cost
Example
Register
Pre Increment Post Increment
a=1; a=1;
b=++a; b=a++; Cache
printf(“%d %d”,a,b); printf(“%d %d”,a,b);
Main memory (Ram+ Rom)
O/p O/p
2 2 2 1 Secondary memory ( Hard disk)
E) Types of errors in program-
Ans. When we write a program error occurs in every stage. An error is
Secondry memory (CD/DVD/Flash etc)
known as Bug and process of removing error is called is De-Bugging. Speed
Types of errors are-
I. Syntactic (grammatical error) - most common and easily removed at As we go up speed and cost increases and as we move down the speed and
time of compilation. cost decreases but quantity of memory used increases.
II. Execution (run time error) - occur while running a program. Most
common errors are- 16. Differentiate between?
a. Numerical overflow or underflow a) While and Do-while
b. Divison by zero
While Do-while
c. Domain error
III. Logical error- they also occur at time of execution and are most 1. Entry controlled loop. 1. Exit controlled loop.
difficult to find. Logical errors are erratic and occur sometimes. It 2. We may never enter the loop if 2. Loop is executed at least once.
requires special techniques to determine error location (where) and initial condition is false
then and finding reason for error and removing it (why).
Techniques for removing errors are-
1. Error isolation
2. Tracing
3. Watch values
4. Break points
5. Stepping
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)
b) Break and Continue e) Compiler and Interpreter
Break Continue Compiler Interpreter
1. Statement used in conjunction 1. Statement used in conjunction 1. Translator used to convert high 1. Translator used to convert
with control statement. with control statement. level program language into high level program language into
machine language. machine language.
2. Used to come out from a 2. Used to skip the current
control statement prematurely. iteration and start the next
iteration. 2. Compiler converts entire program 2. It converts and executes line
is one go. by line.
c) Initialization and Assignment Statement
Initialization Assignment Statement 3. Will not complete even if there is 3. Will stop when first error is
It is the process of assigning It is actually solving an expression a single error in program. encountered.
variable NULL or zero value to and assigning/storing the result in
remove old data which may have 4. It is one time process there after 4. Process is repeated every time
the variable.
undesired effect on result. we run machine language program. program is run.

5. Comparatively very slow.


5. It is very fast.
d) Arithmetic and Relational Operator
Arithmetic Operator Relational Operator e) Structure and Union
1. Five arithmetic operator- +, - 1. four relational operator- Structure Union
,*,/,%. <,<=,>,>=. 1. Heterogeneous data structure 1. Heterogeneous data structure
2. Used to solve arithmetic 2. Used to solve logical defined with keyword struct. defined with keyword union.
expressions. expressions.
2. Amount of memory required in 2. Amount of memory required
3. Result may be integer, float or 3. Result is always numeric value
sum of size of all the members. in always equal to that required
double precision. 1 (True) and 0 (False). by its largest member.
3. Data can be assigned
simultaneously to all the 3. Data can be assigned to one
members. member at a time.

4. Takes large memory. 4. Used to conserve memory.

Example Example
struct node union node
{ char c; { char c;
int i; int i;
float f; float f;
}; };

Size=1+2+4=7 bytes Size=maximum(1,2,4)=4 bytes


Goel Institute of Technology & Managemen, Lucknow
B.Tech., Ist Year
Programming for Problem Solving (KCS-101/201)
17. How macros are defined and called in C. explain with example?
Ans. Macros are single identifiers that are equivalent to expressions,
complete statements or group of statements. Macros resemble functions in
the sense.
Symbolic constant: Macros most common use in that of symbolic constant.
Example: # define PI 3.14
# define TRUE 1
Here symbol PI and TRUE may be used instead of values 3.14 and 1 anywhere
program, during compilation they are replaced by their value.
It is possible to define multiline macros by placing backward slash(\) at end of
each line except last.
Example-
# define loop for(lines=1;lines<=n;++lines)\
{ for (count=1;count<n-lines; count++);\
putchar(‘’);\
for (count=1;count<lines;++count);\
putchar(‘*’);\
printf (‘’\n”);}
It is also possible to include arguments which are enclosed in parenthesis
(without space). When macro is defined in their manner, it appearance within
a program looks like a function call.
Example:
# define sum(x,y) y=x+y;\
printf (‘’%d”,y);

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.

You might also like