Two Mark Questions and Answers
Two Mark Questions and Answers
KOVAIPUDUR, COIMBATORE-641042
DEPARTMENT OF CSE & IT
TWO MARK QUESTIONS AND ANSWERS
SUBJECT CODE : 13H105
SUBJECT
: FUNDAMENTALS OF COMPUTING & CPROGRAMMING
CLASS
: I YEAR
UNIT I
INTRODUCTION TO COMPUTERS
1. What is a computer?
A computer is a data processor that accepts the input data (alphanumeric) or
instructions or both and performs the operations and displays the results of the
operation.
2. What are the advantages of computer?
The main advantages offered by computers are as follows:
High Accuracy
Superior Speed of Operation
Large Storage Capacity
User friendly Features
Portability
Platform independence
Economical in the long term
3. Mention the applications of computer
Education
sports
Advertising
Medicine
Entertainment
Government
Home
Science & Engineering
4. State the characteristics of computers
Speed
Accuracy
Automatic
Endurance
Versatility
Reduction of cost
5. Mention any two recent input & output devices
Input devices:
Touch pad, touch screen
1
Output devices:
Printer, plotters
6. Give the classification of computers.
Computer Type
Mainframe
Year of Introduction
1945
Mini Computer
1965
Micro Computer
1972
Personal Computer
1975
Laptop
1983
Palmtop
1990
Specific Computers
Mark1,B5000,IBM
s/360/370,CRAY-1,UNIVAC
1100,IBM 1401,ICL 1901,ICIM
2900
PDP-8,PDP-11,HP 2100A,TDC
312,TDC 316,HCL s-2/s-4
ORG 2001,ORG 80,WIPRO
86,SUPERMAX
APPLE,ALTAIR
8800,SINCLAIR,IBM PC
TRS-80 Model 100,IBM
5155,Compaq SLT/286, Zenith
Minisport, Mactinosh PowerBook
100,ThinkPad 700
7. Write the full forms of ENIAC, ALU, CU, RAM, ROM, EPROM, EEPROM, BIOS.
ENIAC Electronic Numerical Integrator and Calculator
ALU Arithmetic Logic Unit
CU Control Unit
RAM Random Access Memory
ROM Read Only Memory
EPROM Erasable Programmable ROM
EEPROM - Electrically Erasable PROM
BIOS Basic Input Output System
8. What is a CPU? What is its function?
The Central Processing Unit (CPU) takes data and instructions from the storage
unit and makes all sorts of calculations based on the instructions given and the
type of data provided. It is then sent back to the storage unit.
CPU, the brain of any computer system. It is just like brain that takes all major
decisions, makes all sorts of calculations and directs different parts of the
computer functions by activating and controlling the operations.
9. Define primary storage and secondary storage.
Primary storage is the main memory that holds running program instructions,
data, intermediate results, and results of ongoing processing of job(s). It is fast in
operation, Small Capacity, Expensive. It is Volatile (looses data on power
dissipation)
Secondary storage is the auxiliary memory that holds data and information of
stored jobs. It is slower than primary storage, Large Capacity, Lot cheaper that
primary storage. It is Non volatile (Retains data even without power)
Nassi-Scheiderman
17. Define flowchart.
A flowchart provides an appropriate step to be followed in order to arrive at the
solution to a problem.
It is a program design tool used before writing programs.
A flowchart comprises a set of various standard shaped boxes that are
interconnected by flowlines.
18. What are the limitations of flowchart?
Complex logical problem sometimes becomes difficult for flowchart.
Alterations and modifications redraw flowchart completely
Reproduction of symbols becomes a problem
The essentials of what has to be done can easily be lost in the technical details of
how it is to be done.
19. Define a pseudocode.
Pseudocode, like step-form written statement of an algorithm using a restricted and
well defined vocabulary.
It is similar to a 3GL.
No standard but easy to read and use.
21. What is a sequence control structure?
Sequence means that each step or process in the algorithm is executed in the specify
order.
Eg. Algorithm to add any two numbers
Step 1 Accept the first integer as input from the user (integer1).
Step 2 Accept the second integer as input from the user (integer2).
Step 3 Calculate the sum of two integer (integer3= integer1+ integer2).
Step 4 Display the integer3 as the result
22. What is relocation?
It means adjustment of all address dependent locations such as address constant. It is
simpler in moving a program from one area to another in main memory.
23. What is a linker ?
Linking resolves symbolic references between the object programs.
References to build-in functions and global data requires linking in C eg. In
FORTRAN , COBOL are translated separately so subprogram cells and common
variables requires linking.
Linking makes the addresses of programs known to each other so that transfer of
control form one subprogram to another or a main program takes place during
execution.
24. What are the basic symbols used in flowchart?
Start or end of the program
Computational steps or processing function of a program
5
Display
Accuracy- multiple algorithm gives correct solution but only some algorithms
give actual output.
Sequence- procedure of an algorithm must form in a sequence.
2. What are the Groups used to perform logic constructions?
1. Sequence
2. Selection (If-then-else and case structure)
3. Iteration (while-do and repeat-until structure)
3.Define Sequencial construction.
Logic flow of pseudo code is from top to bottom
No conditional statements, jump or branch instructions used
Instructions are executed in sequential order
Simplest way to represent arithmetic or input/output statements
4. Define Selection construction.
Also called as decision logic
Used for decision making purposes
Tasks are performed if the given conditions are satisfied
Otherwise, alternative tasks are carried out
While constructing pseudo code, statements used for selection
logic are:
(i) If-then statement
(ii) If-then-else statement
(iii) Case statement
5. What are the Main reasons for using loop statements?
To easily read, write or process large data. Example: Array processing
To perform iterative computing
Business application, etc
6. What are the Classification of loops?
Definite loop
Indefinite loop
1. Definite loop:
Initial value within the loop is changing to meet the termination condition
Boolean expression is changing to meet the termination condition
2. Indefinite loop:
Loop construction never meets the termination condition
External operations such as reset, reboot are done to terminate the program
7. Give the pseudo code for if-then structure:
If condition then
Process 1
Else
Process 2
End if
7
14.
3
4
5
6
7
Indicators
Program development
time
Programmers
skill
required
Orientation
Ease of modification
Speed of processing
Memory requirements
Portability of programs
Applications
High
Much lower
Towards computers
Difficult
Very high
Minimum
Programs are confined
machine
Operating systems (OS)
Towards humans
Very easy
Slower
Often significant
to Application
Application programs
10
The user moves or copies a document, program or other data from a computer to
the internet
22. Differentiate between Online and offline:
Online means connected to the world wide web via internet
Any activity undertaken while the computer is connected to another computer
or network is said to be online
Offline means user is no longer connected to the remote computer
Offline is the opposite of online. It refers to the actions performed when the
user is not connected to another computer or a network like the internet
23. List out some of the Internet services:
World wide web (WWW)
Electronic mail (E-mail)
Internet relay chat (IRC)
Chatting and instant messaging
Internet telephony
Video Conferencing
24. What are the different Types of internet connection?
Dial-up
ISDN
Cable
Modem
Leased line
DSL
Broadband
25. What is an algorithm?
An algorithm is part of the plan for computer program. It is an effective procedure
for solving a problem is a finite number of steps.
It helps the programmer in breaking down the solution of a problem into number
of sequential steps.
26. What are the ways of representing an algorithm?
Three different ways such as
Pseudocode
Flow chart
Nassi-Scheiderman
27. Define flowchart.
A flowchart provides an appropriate step to be followed in order to arrive at the
solution to a problem.
It is a program design tool used before writing programs.
A flowchart comprises a set of various standard shaped boxes that are
interconnected by flowlines.
11
12
comment lines. These are not executable, the compiler is ignored any thing in
between /* and */
Ex: // Sample comment line
/* program for adding two numbers*/
3. What is meant by C tokens?
The tokens are usually referred as individual text and punctuation in a passage of
text. The C language program can contain the individual units call the C tokens.
Ex: operator, string, constant, identifier
4. Define data types.
Data type is the type of the data, that are going to access within the program. C
supports different data types, each data type may have predefined memory
required and storage representation.
5. Define identifiers.
Identifiers are names given to various program elements, such as variables,
functions and arrays etc.
Ex: basic_pay, num1, sum
6. What are keywords?
Keywords are certain reserved words, that have standard and pre-defined meaning
in C. These keywords can be used only for their intended purpose.
Ex: int, float, static, extern, const
7. Why do we need to use comments in programs?
To increase readability and understandability.
To help users in debugging and testing.
8. Write down the syntax for Declaring a variable
Syntax: Datatype variablename;
Ex:
int a;
9. Write the use of scanf & printf with example?
The scanf statement is used to get the input from the standard input
device..
The printf statement is used to print the result on the standard output
device.
Example:
scanf(%d, &a);
printf(Result:, a);
10. What is meant by variables? How and where are the variables
declared?
A variable is an identifier that is used to represent some specified type of
information within a designed portion of the program.
Variables are declared along with its data type at the beginning of the
program.
Ex: data_type variable _name;
Where data type represents the type of data,
variable_name is the valid C identifier.
13
The items whose values cannot be changed during the execution of program are
called constants.
Ex: 10, 10.2, a, it
The value stored in the variable can be changed during the
execution of the program.
15. Define String constants.
A string constant is a sequence of characters enclosed in double quotes, the
characters may be letters, numbers, special characters and blank spaces etc. at the
end of string \0 is automatically placed.
Ex: sangee, 123, , $%^
16. List out the various backslash character constants.
\n
- Newline
\t
- Tab
\b
- Backspace
\f
- Form feed
\r
- Carriage return
\a
- Alert
\
- Single quote
\
- Double quote
\\
- Backslash
17. What is an operator and operand?
An operator is a symbol that specifies an operation to be performed on operands.
Ex: *, +, -, / are called arithmetic operators.
12. The data items that operators act upon are called operands.
Ex: a+b; In this statement a and b are called operands.
18. What are the types of operator?
Arithmetic operators
Relational operators
Logical operators
Assignment operators
Increment and decrement operators
Conditional operator(Ternary operator)
Bitwise operators
Special operators.
19.What is Ternary operator?
Ternary operator is a conditional operator with symbols? and:.
Syntax: variable = exp1? exp2: exp3
If the exp1 is true, variable takes the value of exp2. if the exp1 is false,
variable takes the value of exp3.
15
13.
The statement will be executed repeatedly as long as the expression is true (i.e., as
long expression has a nonzero value). This statement can be simple or compound,
though it is usually a compound statement.
20
Loops like if-else statements can be nested one within another. The inner and
outer loops need not be generated by the same type of control structure. It is
essential that one loop can be completely embedded within the other - there can
be no overlap.
2.
Each loop must be controlled by a different index. Moreover nested control
structures can involve both loops and if - else statements.
3.
A loop can be nested within an if-else statement and an if-else statement can
be nested within a loop. The nested structures may be as complex as necessary, as
determined by the program logic.
51. What is the purpose of the switch statement?
The switch statement causes a particular group of statements to be chosen from
several available groups. The selection is based upon the current value of an
expression which is included within the switch statement.
The general form of the switch statement is
switch (expression) statement
where expression results in an integer value. Note that expression may also be of
type char, since individual characters have equivalent integer values.
52. Define break statement. Give an example.
The break statement is used to terminate loops or to do -while, or switch
statement. The break statement is written simply as
break;
without any embedded expressions or statements.
Eg.
switch (choice = toupper(getchar0))
{
case ' R :
printf( "RED" ) ;
break;
case ' W ' :
printf("WH1TE");
break;
case B ' :
printf ( "BLUE") ;
break;
default :
printf ( ERROR");
break;
}
53. Define Continue Statement. Give an example.
The continue statement is used to bypass the remainder of the current pass
through a
loop. The loop does not terminate when a continue statement is
21
encountered. Rather, the remaining loop statements are skipped and the
computation proceeds directly to the next pass through the loop.
The continue statement can be included within a while, a do - while or a f o r
statement. It is written simply as
continue;
without any embedded statements or expressions.
Eg:
for(count = 1; x <= 100; ++count) {
scanf ( "%f &x) ; 'I,
if (x < 0) {
printf("ERR0R - NEGATIVE VALUE FOR X " ) ;
continue;
}
54. Define Comma operator.
The comma operator (,) which is used primarily in conjunction with the for
statement. This operator permits two different expressions to appear in
situations where only one expression would ordinarily be used.
for( expression 7a, expression 7b; expression 2; expression 3) statement
where expression la and expression 7b are the two expressions, separated by
the comma operator,
where only one expression (expression I) would normally appear. These two
expressions would typically initialize two separate indices that would be used
simultaneously within the for loop.
55. What is palindrome?
A palindrome is a word, phrase or sentence that reads the same way either
forward or backward. For example, words such as noon, peep, and madam are
palindromes.
56. Define goto statement.
The goto statement is used to alter the normal sequence of program execution
by transferring control to some other part of the program.
In its general form, the goto statement is written as
goto label;
where label is an identifier that is used to label the target statement to which
control will be transferred.
Eg.
scanf ( "%fI" , &x) ;
while (x <= 100) {
.....
if ( x < 0) goto errorcheck;
.....
scanf ( "%fI" , &x) ;
}
error detection routine */
22
errorcheck: {
printf("ERROR - NEGATIVE VALUE FOR X " ) ; }
UNIT IV & V
ARRAYS AND STRINGS
1. What is a Pointer in C?
A pointer is a variable that represents the location (rather than the value) of a data
item, such as a variable or an array element.
A pointer is a data type whose value refers directly to (or "points to") another
value stored elsewhere in the computer memory using its address.
A pointer references a location in memory, and obtaining the value at the location
a pointer refers to is known as dereferencing the pointer
2. What are the advantages of using Pointers in C?
5. Pointers can handle arrays and data table efficiently.
6. Pointers support dynamic memory management.
7. Pointer helps to return multiple values from a function through function argument.
8. Pointer increases program execution speed.
9. Pointer is an efficient tool for manipulating structures, linked lists, queues stacks
etc.
3. What kind of information is represented by a pointer variable?
Pointer Variable is a variable that contains the memory location(address) of
another variable or an array (or anything else in memory). Effectively, it points to
another
memory
location.
4. List out some of the operations on pointers?
o A pointer variable can be assigned the address of an ordinary variable.
o A pointer variable can be assigned the value of another pointer variable provided
both pointers point to objects of the same data type.
o An integer quantity can be added to or subtracted from a pointer variable.
o A pointer variable can be assigned a null (zero) value.
o One pointer variable can be subtracted from another provided both pointers point
to elements of the same array.
o Two pointer variables can be compared provided both pointers point to objects of
the same data type.
5. Write notes on Address operator an indirection operator.
Suppose 'a' is a variable that represents some particular data item. The
compiler will automatically assign memory cells for this data item. The data item
can be accessed if we know the location of the first memory cell. The address of
23
as memory location can be determined by the expression &v, where & is a unary
operator called the address operator, that evaluates the address of its operand.
Now let us assign the address of 'a' to another variable, Thus
pa= &a;
This new variable is called a pointer to 'a', since it points to the
locations where 'a' is stored in memory. However, pa represents as address, not its
value. Thus, pa is referred to as a pointer variable.
Address of a value of a
pa
a
The data item represented by 'a' ( i.e the data item stored in as
memory cells) can be accessed by the expression *pa, where * is a unary operator,
called the indirection operator, that operates only on a pointer variable. Therefore,
*pa and 'a' both represent the same data item (ie the contents of the same memory
cells).
Further more if we write pa= &a and b = *pa, then 'a' and 'b' will both
represents the same value i.e the value of a will indirectly be assigned to 'b'
A pointer declaration may be written in general terms as datatype *ptr; Where ptr
is the name of the pointer variable and data-type refers to the data type of the
pointers object.
For example,
float a,b;
float *pb;
The first line declares a and b to be floating-point variables. The second line
declares pb to be a pointer variable whose object is a floating-point quantity i.e.
'pb' point to a loating point quantity. 'pb' represents an address, not a floatingpoint quantity. Within a variable declaration, a pointer variable can be initialized
by assigning it the address of another variable.
Pointers are often passed to a function as arguments. This allows data items
within the calling portion of the program to be accessed by the function, altered
within the function, and then returned to the calling portion of the program in
altered form.
11.Differentiate Actual & Formal Arguments.
Actual parameters are parameters as they appear in function calls.
Formal parameters are parameters as they appear in function declarations.
A parameter cannot be both a formal and an actual parameter, but both formal parameters
and actual parameters can be either value parameters or variable parameters.
24
#include <stdio.h>
int main (void);
int calculate_bill (int, int, int);
int main()
{
int bill;
int fred = 25;
int frank = 32;
int franny = 27;
bill = calculate_bill (fred, frank, franny);//actual parameters.
printf("The total bill comes to $%d.00.\n", bill);
}
exit (0);
25
int main()
{
int num1=50,num2=70;
interchange(num1,num2);
printf(\n number1:%d,num1);
printf(\n number2:%d,num2);
return(0);
}
output:
number1:50
number2:70
explanation:
A: call by value:
1)while passing parameter using call by value,Xerox copy of original parameter is
created and passed to the called function.
2)any update made inside method will not affect the original value of variable in
calling function.
3)in the above example num1&num2 are the original values is value passed to the
function and these vaues are copied into number1,number2 variable of sum function
respectively.
4)as their scope is limited to only function so they cannot alter the values inside main
function.
B:call by reference:
eg:
#include<stdio.h>
void interchange(int * num1,*num2)
{
int temp;
temp=*num1;
num1=*num2;
num2=temp;
}
int main()
{
int num1=50,num2=70;
interchange(&num1,&num2);
printf(\n number1:%d,num1);
printf(\n number2:%d,num2);
return(0);
}
26
output:
number1:70
number2:50
explanation:
call by address:
1.while passing parameters using call by address scheme,we are passing the actual
address of the variable to the called function.
2.any updates made inside the called function will modify the original copy since we are
directly modifying the content of the exact memory location.
summary of call by value and call by reference
point
copy
modification
Call by value
Duplicate copy of original
parameter is passed
No effect on original
parameters after modifying
parameter in function
Call by reference
Actual copy of original
parameter is passed
Original parameter gets
effected if value of parameter
changed inside function
UNIT V
13.What is a structure? How does a structure differ from an array?
Structure declarations are somewhat more complicated than array
declarations, since a structure must be defined in terms of its individual members. In
general terms, the composition of a structure may be defined as
struct tag
{
member 7;
member 2;
.....
member m;
};
Array elements are of the same data type whereas the individual elements
can differ in type in structure.
12. How is an array of structures initialized?
struct account
{
int acct-no;
char acct-type;
char name[80];
float balance;
27
The typedef feature allows users to define new data-types that are
equivalent to existing data types. Once a user-defined data type has been
established, then new variables, arrays, structures, etc. can be declared in
terms of this new data type.
where type refers to an existing data type (either a standard data type, or
previous user-defined data type),and new- type refers to the new user-defined
data type. It should be understood, however, that the new data type will be
new in name only. In reality, this new data type will not be fundamentally
different from one of the standard data types.
14.How can an entire structure be passed to a function and returned from a function.?
There are several different ways to pass structure-type information to or from
a function. Structure members can be transferred individually, or entire
structures can be transferred.
The mechanics for carrying out the transfers vary, depending on the type of
transfer (individual members or complete structures) and the particular
version of C.
Individual structure members can be passed to a function as arguments in the
function call, and a single structure member can be returned via the return
statement.
To do so, each structure member is treated the same as an ordinary singlevalued variable.
15.What is a union? How does a union differ from a structure?
Unions, like structures, contain members whose individual data types may
differ from one another. However,the members within a union all share the
28
29