GE6151 Computer Programming Question Bank: Unit I - Introduction Part A (2 Marks)
GE6151 Computer Programming Question Bank: Unit I - Introduction Part A (2 Marks)
UNIT I – INTRODUCTION
PART A (2 MARKS)
1. Define computers?
Computer is a fast operating electronic device, which automatically accepts and store
input data, processes them and produces results under the direction of step by step
program.
Based on physical size, performance and application areas, we can generally divide
computers into four major categories:
Micro computer
Mini Computer
Mainframe computer and
Super Computer
Arithmetic logic unit, the part of a computer that performs all arithmetic
computations, such as addition and multiplication, and all logical operations such s
comparison operations. The ALU is one component of the CPU (central processing
unit).
8. What are the functions in the input unit?
An input device is a device that is used to input data or information into a computer.
Some examples of input devices include:
Keyboards.
Computer mice.
Light Pen.
Digitizer.
Touchpad.
Each symbol of different shapes denotes different shapes denote different types of
instructions. The program logic through flowcharts is made easier through the use of
symbol that has standardized planning.
“Pseudo” means imitation of false and “code” refers to the instruction written in the
programming language. Pseudo code is programming analysis tool that is used for
planning program logic.
25. Draw the flowchart to find the maximum among three numbers (JAN2009)
PART B
16MARKS
6. Define Flow. Mention the guide lines to be followed to draw a flow chart. List
out the Advantage and disadvantages (16)
UNIT-II
2 MARKS
Compilation refers to the processing of source code files (.c, .cc, or .cpp) and the
creation of an 'object' file. This step doesn't create anything the user can actually run.
Instead, the compiler merely produces the machine language instructions that
correspond to the source code file that was compiled.
Linking refers to the creation of a single executable file from multiple object files. In
this step, it is common that the linker will complain about undefined functions
(commonly, main itself). During compilation, if the compiler could not find the
definition for a particular function, it would just assume that the function was defined
in another file. If this isn't the case, there's no way the compiler would know it doesn't
look at the contents of more than one file at a time. The linker, on the other hand, may
look at multiple files and try to find references for the functions that weren't
mentioned.
The constants refer to fixed values that the program may not alter during its execution.
These fixed values are also called literals.
Constants can be of any of the basic data types like an integer constant, a floating
constant, a character constant, or a string literal. There are also enumeration
constants as well.
The constants are treated just like regular variables except that their values cannot be
modified after their definition.
4. What are the different data types available in „C‟?
Enumerated data type variables can only assume values which have been previously
declared.
Example :
enum month { jan = 1, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec };
Local
These variables only exist inside the specific function that creates them. They are
unknown to other functions and to the main program. As such, they are normally
implemented using a stack. Local variables cease to exist once the function that
created them is completed. They are recreated each time a function is executed or
called.
Global
These variables can be accessed (ie known) by any function comprising the program.
They are implemented by associating memory locations with variable names. They do
not get recreated if the function is recalled.
Arithmetic Operators
Relational Operators
Logical Operators
Bitwise Operators
Assignment Operators
Misc Operators
++a means do the increment before the operation (pre increment) a++ means do the
increment after the operation (post increment)
Example:
a=5;
x=a++; /* assign x=5*/ y=a; /*now y assigns y=6*/ x=++a; /*assigns x=7*/
13.Distinguish between while..do and do..while statement in C. (JAN 2009)
While DO..while
(i) Executes the statements within the while block (i) Executes the statements within thwhile block at
if only the condition is true. least once.
(ii) The condition is checked at the starting of the (ii) The condition is checked at the end of the loop
loop
Statement Description
20.Write short notes about main ( ) function in ‟C‟ program. (MAY 2009)
The program execution starts from the opening brace „{„ and ends with
closing brace „}‟, within which executable part of the program exists.
21.Define delimiters in „C‟.
Delimiters Use
: Colon
; Semicolon
( ) Parenthesis
[ ] Square Bracket
{ } Curly Brace
# Hash
, Comma
22. Why header files are included in „C‟ programming?
· This section is used to include the function definitions used in the program. · Each
header file has „h‟ extension and include using ‟# include‟ directive at the beginning
of a program.
(ii) If the condition is true, it executes (ii) Executes the statements within the
(iii) If the condition is false then it stops (iii) If the condition is false the control is
the execution the statements. transferred to the next statement of the loop.
27.Differentiate between formatted and unformatted you input and output
functions?
These functions allow us to supply the input in a fixed format and let us obtain the
output in the specified form. Formatted output converts the internal binary
representation of the data to ASCII characters which are written to the output file.
There are several standard library functions available under this category-those that
can deal with a string of characters. Unformatted Input/Output is the most basic form
of input/output. Unformatted input/output transfers the internal binary representation
of the data directly between memory and the file.
UNIT II
(16 Marks)
1. Define C language. Mention the basic structure of C programs with
explanation. (16)2. Discuss about the various data types in „C‟. (MAY 2009)
An array is a group of similar data types stored under a common name. An array is
used to store a collection of data, but it is often more useful to think of an array as a
collection of variables of the same type.
Example: int a[10];
You can initialize array in C either one by one or using a single statement as
follows:
The number of values between braces { } cannot be larger than the number of
elements that we declare for the array between square brackets [ ]. Following is
an example to assign a single element of the array:
4.Size of(array name) gives the 4.Sezeof(pointer name) returns the number of bytes used
to store the pointer variable.
number of bytes occupied by the array.
All elements of an array share the same name, and they are distinguished form one
another with help of an element number. Any particular element of an array can be
modified separately without disturbing other elements.
8.Define Strings.
Strings:
The group of characters, digit and symbols enclosed within quotes is called as Stirng
(or) character Arrays. Strings are always terminated with „\0‟ (NULL) character. The
compiler automatically adds „\0‟ at the end of the strings.
Example:
char name[]={„C‟,‟O‟,‟L‟,‟L‟,‟E‟,‟G‟,‟E‟,‟E‟,‟\0‟}
The C library supports a function that converts a string of digits into their
integer values. The function takes the form
x= atoi(string)
Example:
typedef int hours: hours hrs;/* Now, hours can be used as new datatype */
Insertion sort.
Merge Sort.
Quick Sort.
Radix Sort.
Heap Sort
Selection sort
Bubble sort
A sorting algorithm that works by first organizing the data to be sorted into a special
type of binary tree called a heap. The heap itself has, by definition, the largest value at
the top of the tree, so the heap sort algorithm must also reverse the order. It does this
with the following steps:
1.Remove the topmost item (the largest) and replace it with the rightmost leaf.
The topmost item is stored in an array.
3.Repeat steps 1 and 2 until there are no more items left in the heap.
15. Define Bubble sort.
Searching for data is one of the fundamental fields of computing. Often, the difference
between a fast program and a slow one is the use of a good algorithm for the data set.
Naturally, the use of a hash table or binary search tree will result in more efficient
searching, but more often than not an array or linked list will be used. It is necessary
to understand good ways of searching data structures not designed to support efficient
search.
17.Mention the various types of searching techniques in C
Linear search
Binary search
18.What is linear search?
In Linear Search the list is searched sequentially and the position is returned if the key
element to be searched is available in the list, otherwise -1 is returned. The search in
Linear Search starts at the beginning of an array and move to the end, testing for a
match at each item.
1.Define array. Explain the array types with an example program for each type.
2. Explain about multi dimensional array with example.
3. Explain String Array with example program.
4. Explain the standard string functions with example to support each type.
5. Write a C program to do the matrix addition using C.
6. Write a program for matrix multiplication in c
7. Write a C program to find out transport of a matrix.
UNIT IV 2 MARKS
A function is a group of statements that together perform a task. Every C program has
at least one function which is main(), and all the most trivial programs can define
additional functions.
Defining a Function:
b) Function Callings:
The user-defined functions can be called inside any functions like main(),user-
defined function, etc.
c) Function Definition:
The function main () invokes other functions within it. It is the first function to be
called when the program starts execution.
Macros are more efficient (and faster) than function, because their corresponding code
is inserted directly at the point where the macro is called. There is no overhead
involved in using a macro like there is in placing a call to a function.
However, macros are generally small and cannot handle large, complex coding
constructs. In cases where large, complex constructs are to handled, functions are
more suited, additionally; macros are expanded inline, which means that the code is
replicated for each occurrence of a macro.
a) In call by value, the value of actual agreements a) In call by reference, the address of actual
is passed to the formal arguments and the operation argurment values is passed to formal argument
is done on formal arguments. values.
b) Formal arguments values are photocopies of b) Formal arguments values are pointers to the
actual arguments values. actual argument values.
c) Changes made in formal arguments valued do c) Since Address is passed, the changes made in the
not affect the actual arguments values. both arguments values are permanent
void recursion()
{
recursion(); /* function calls itself */
}
int main()
{
recursion();
}
#include <stdio.h>
When the above code is compiled and executed, it produces the following result:
Factorial of 15 is 2004310016
11. What is a Pointer? How a variable is declared to the pointer? (MAY 2009)
int main()
{
recursion();
}
#include <stdio.h>
When the above code is compiled and executed, it produces the following
result:
Factorial of 15 is 2004310016
UNIT IV
16 Marks
2. Explain various types of functions in detail with an example program for each
type
3. Define Recursion in C. Explain the concept of recursion with example.
An array is a collection of data items of same data A structure is a collection of data items of different
type.Arrays can only be declared. data types. Structures can be declared and defined.
An array name represents the address of the starting A structrure name is known as tag. It is a
element.
Shorthand notation of the declaration.
An array cannot have bit fields. A structure may contain bit fields.
Structure Union
Every member has its own memory. All members use the same memory.
All members occupy separate memory location, Different interpretations for the same memory
hence different interpretations of the same memory location are possible.
location are not possible.
Conservation of memory is possible
Consumes more space compared to union.
3. Define Structure in C.
C Structure is a collection of different data types which are grouped together and
each element in a C structure is called member.
Many structure variables can be declared for same structure and memory will be
allocated for each separately.
It is a best practice to initialize a structure to null while declaring, if we don‟t assign
any values to structure members.
A structure type is usually defined near to the start of a file using a typedef statement.
typedef defines and names a new type, allowing its use throughout the program.
typedefs usually occur just after the #define and #include statements in a file.
This defines a new type student variables of type student can be declared as follows.
student st_rec;
5. How to Declare a members in Structure?
struct tag_name
{
A union is a special data type available in C that enables you to store different data
types in the same memory location. You can define a union with many members, but
only one member can contain a value at any given time. Unions provide an efficient
way of using the same memory location for multi-purpose.
To define a union, you must use the union statement in very similar was as you did
while defining structure. The union statement defines a new data type, with more than
one member for your program. The format of the union statement is as follows:
union [union tag]
{
To access any member of a union, we use the member access operator (.). The
member access operator is coded as a period between the union variable name and the
union member that we wish to access. You would use union keyword to define
variables of union type
Macro Inclusion
Conditional Inclusion
File Inclusion
A storage class defines the scope (visibility) and life time of variables and/or
functions within a C Program.
Register is used to define local variables that should be stored in a register instead of
RAM. This means that the variable has a maximum size equal to the register size
(usually one word) and cant have the unary '&' operator applied to it (as it does not
have a memory location).
{
register int Miles;
}
Static is the default storage class for global variables. The two variables below (count
and road) both have a static storage class.
The example above defines two variables with the same storage class. auto can only
be used within functions, i.e. local variables.
The C Preprocessor is not part of the compiler, but is a separate step in the
compilation process. In simplistic terms, a C Preprocessor is just a text substitution
tool. We'll refer to the C Preprocessor as the CPP.
Example:
#define Substitutes a preprocessor macro
#include Inserts a particular header from another file
16. Define Macro in C.
For example:
1 #ifdef TABLE_SIZE
2 int table[TABLE_SIZE];
3 #endif
1 #include "file"
2 #include <file>
Where number is the new line number that will be assigned to the next code line. The
line numbers of successive lines will be increased one by one from this point on.
UNIT V
16MARKS