Vous êtes sur la page 1sur 41

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.

IN
CSEITQUESTIONS.BLOGSPOT.IN

GE6151 COMPUTER PROGRAMMING


QUESTION BANK
UNIT I
Short Questions
Generation and Classification of Computers- Basic Organization of a
Computer
1) List the four parts of a complete computer system.
(i) Hardware (ii) software (iii) data (iv) users
2) What are the advantages and disadvantages of I generation computers?
Advantages: These were the fastest at their time. They were able to
execute complex calculations in an efficient manner.
Disadvantages: operations depended on machine language. Therefore,
they are not very easy to program. They were not flexible for many
different application. They were bulky and produced lot of heat.
3) Give the advantages and disadvantages of II generation computers.
Advantage: they were the fastest at that time. Used assembly language
so
programming was easier. They could be transported from one place to
other. Disadvantages: They were required to be placed in airconditioned rooms. The cost of these computers were so high that home
users cannot afford to buy. They were only special purpose computers
and so, they can not be used for general purpose applications.
4) Give the advantages and disadvantages of III generation computers.
Advantages: fastest at their time. Computational time was greatly
reduced
and thus very productive. There were easily transportable. They could
be installed easily and occupied less space. They were used both
business and scientific application and thus there were considered
general purpose computers.
Disadvantages: storage capacity was not high. Overall cost was high.
They were still to be placed in air-conditioned rooms.
5) Give the advantages and disadvantages of IV generation computers.
Advantages: The use of VLSI technology made these computers powerful
in
speed and accuracy. Storage capacity was very high. They were highly
reliable and required less maintenance. They were highly user friendly.
Programs used were highly portable to different computers and they are
1

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN
CSEITQUESTIONS.BLOGSPOT.IN

very versatile. They require less power to operate.


Disadvantage: very complicated mechanism is needed to assemble these
computers. Working on these computers depends on the instructions
given by the programmer.
6) Mention the advantages and of V generation computers over IV.
Advantages: Development of Personal Digital Assistant(PDAs).
Parallel processors. Invention of Optical disk technology.
Development of internet. The users of these computers find it very
comfortable to use because of several additional multimedia features.
7) Mention the advantages and of VI generation computers over V
Advantages: Development of Personal Digital Assistant(PDAs).
Parallel processors. Invention of Optical disk technology.
Development of internet. The users of these computers find it very
comfortable to use because of several additional multimedia features.
8) Differentiate between analog and digital computers.
Analog
Digital
The data is represented in the form
of electrical pulses.
The electronic circuit employed in
the analog computer is an
operational amplifier.

Data is stored in terms of 0s and 1s.


This consists of ALU, control unit, a
memory unit and I/O units.

9) Mention the various types of computers according to their


size and capability.
Microcomputers
Minicomputers
Mainframe computers
Super computers
10) Mention the different categories of computers made for individual users.
a) Desktop computers
b) Workstations
c) Notebook computers
d) Tablet computers
e) Handheld computers
f) Smart phones
11)
List out the difference between mainframe computers and super
2

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN
CSEITQUESTIONS.BLOGSPOT.IN

computer. Mainframe Computer: Used by large business organisation


employing very
huge applications such as financial transaction processing, consumer
statistics, enterprise resource planning. The term refers to huge cabinet with
a

central processor and a huge main memory.


Super Computers: It is the fastest type of computers that can perform
complex operations at a very high speed. They are used for (i) weather
forecasting (ii) Graphics animations (iii) Nuclear energy establishments
(iv) petroleum exploration. Super computers employ the fastest
processors and they are large in number very large memory and storage is
being used. Many optimising techniques to enhance the performance of
the processor by pipeling and parallelism methods.
12) Draw the block diagram of a computer.

13) Distinguish between RAM and ROM.


RAM: As new data is entered into the computer, it is also stored in
memory- but only temporarily. Data is both written to and read from
this memory. RAM is volatile, meaning that it loses its contents when
the computer is shut off or if there is a power failure.
3

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN
CSEITQUESTIONS.BLOGSPOT.IN

ROM: It permanently stores its data, even when the computer is shut
off. ROM is called non-volatile memory because it never loses its
contents.
ROM holds instructions that the computer needs to operate.
Number Systems - Binary Decimal Conversion
14) What is the weight of the digit 6 in each of the following decimal
numbers?
(a) 1386 (b) 54,692 (c) 671,920
Ans: (a) 6 (b) 600 (c)
15) Express each of the following decimal numbers as a power of ten:
(a) 10
(b) 100
(c) 10,000 (d) 1,000,000
Ans: (c) 1104 + 0103 + 0102 + 0101 + 0100
16) Give the value of each digit in the following decimal numbers:
(a) 471
(b) 9356 (c) 125,000
Ans: (b) 9 9000 , 3 300 , 5 50, 6 - 6
17)
How high can you count with four decimal
digits? 9999
18) Convert the following binary numbers to decimal:
(a) 1110 (b) 1010
(c) 11100 (d) 10000 (e) 10101
Ans (e) 21
19) Convert the following binary numbers to decimal:
(a) 110011.11
(b) 101010.01
(c) 1000001.111
Ans: (c) For decimal 1 26 + 0 25 + ...+ 1 = 65 for fractional:
1 2-1 + 1 2-2 + 1 2-3. Thus 65.875
20)
What is the highest decimal number that can be represented by
each of the following numbers of binary digits (bits)?
(a) two (b) three
(c) four (d) five (e) six
3
ans: (b) 7(2 1)
21) How many bits are required to represent the following decimal numbers?
(a) 17 (b) 35 (c) 49 (d) 68 (e) 81 Ans: (c) 49 = 110001 so minimum 6 bits
are needed.
22) Generate the binary sequence for each decimal sequence:
(a) 0 through 7 (b) 8 through 15 (c) 16 through 31 Ans:
(b) 1000,1001,1010,1011,1100,1101,1110,1111
Decimal-to-Binary Conversion
23)
Convert each decimal number to binary(by using the sum-ofweights method):
4

(a) 10
1 (b) 17
0 (c) 24 (d) 48 (e) 61 Ans: (c) 24 = 16 + 8 = 12 + 12 + 02 +
02 + 02 so 24 = 110002
4

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN
CSEITQUESTIONS.BLOGSPOT.IN

24)
Convert each decimal fraction to binary using repeated
multiplication by 2 method
(a) 0.98 (b) 0.347 (c) 0.9028
Ans: (b) 0.3472=0.694; 0.6942=1.388; .3882=0.776;
0.7762=1.552; 0.5522=1.104 and so on.
So, approximately, 0.347 = .01011
25)
Convert each decimal fraction into binary by using the sum-ofweights method:
(a) 0.32 (b) 0.246 (c) 0.0981
Binary Arithmetic
26) Add the binary numbers:
(a) 11 + 01 (b) 10 + 10 (c) 101 + 11 (d) 111 + 110 (e) 1001 + 101 (f) 1101
+ 1011

27) Perform the following binary multiplications:


(a)11 11 (b) 100 10 (c) 111 101
1's and 2's Complements of Binary
Numbers
28) Determine the l's complement of each binary number:
(a)101 (b) 110 (c) 1010
Ans: (a) 010 (b) 001 (c) 0101
29)
Determine the 2's complement of each binary number using
either method:
(a) 10
(b) 111
(c) 1001 (d) 1101
Ans: (a) 10 (b) 001 (c) 0111 (d) 0011
Signed Numbers
30)
Express each decimal number in binary as an 8-bit signmagnitude number:
(a) +29 (b) -85 (c) + 100 (d) -123
Ans: (a) 00011101 (b) 10101011 (c) 01100100 (d) 10000101
31)
Express each decimal number as an 8-bit number in the l's
complement form:
(a)-34 (b) +57 (c) -99 (d) +115 Ans: (a) 11011101
(b) 00111001 (c) 10011100
32)
Determine the decimal value of each signed binary number in
the 2's complement form:
(a) 10011001 (b) 01110100 (c) 10111111
Ans: (a) -103 (b) +116 (c) -65 Arithmetic
5

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN
CSEITQUESTIONS.BLOGSPOT.IN

Operations with Signed Numbers


33) Convert each pair of decimal numbers to binary and add using the 2's
complement form:
(a) 33 and 15 (b) 56 and -27and 25 (c) -110 and -84
Ans: 2s complement of 33 = 00100001+
2s complement of 15
= 00001111
00110000
2s complement of 56 = 00111000
2s complement of -27 =
11100101

48

00011101(no end carry)


2s complement of 25 = 00011001

Result = 00110110
54

29

Hexadecimal Numbers
34) Convert each hexadecimal number to binary:
(a) 3816 (b) 5916 (c) A1416 (d) 5C816
Ans: (a) 11 1000 0001 0110 (d) 0101 1100 1000 0001 0110
35)
Convert each binary number to
hexadecimal: (a)1110 (b) 10
ans: (a) E (b) 2
36) Convert each octal number to decimal:
(a) 128 (b) 278 (c) 568 (d) 648 (e) 1038 Ans: (a) 10 (c) 46 (d) 52 (e) 67
37) Convert each octal number to binary:
(a) 138
(c) 1018 (d) 3218 (e) 5408
(b) 578
Ans: (a) 001 011 (b) 101 111 (c) 001000001 (e) 101 100 000
38) Convert each binary number to octal:
(a) 111
(b) 10
(c) 110111 (d) 101010
Ans: (a) 7 (b) 2 (c) 67 (d) 52
39) Convert each of the following decimal numbers to 8421 BCD:
(a) 10
(b) 13
(c) 156
(d) 21
Ans: (a) 0001 0000 (c) 0001 0101 0110 (e) 0010 0101
40) Convert each of the BCD numbers to decimal:
(a) 10000000
(b) 001000110111
Ans: (a) 80 (b) 237
6

(e) 25

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN
CSEITQUESTIONS.BLOGSPOT.IN

41) Convert each pair of decimal numbers to BCD, and add as indicated:
(a) 28 + 23 (b) 65 + 58 (c) 113 + 101 (d) 295 +
157 Ans: (a) 28 in BCD = 0010 1000
23 in BCD = 0010 0011

Carry

0100 1011
0001 0110
0101 0001

> 9 So add 6

51 is the result.

42) Convert each binary number to Gray


code: (a)10011 (b) 11011
Ans: (a) 11010 (b) 10110
43) Convert the Gray code to binary
(a) 1011 (b) 11010
Ans: (a) 1101 (b)
10011
Problems. Need for logical analysis and thinking
44) What are the three steps in solving a problem?
(i) Understand the problem (ii) Find the connection between the
data and the unknown devise a plan(iii) carry out the plan
and examine the solution obtained.(iv) look back check if
there are more approaches.
45) State the purpose of problem solving through computers.
Computers are very fast in solving problems. The Computer calculates
with great accuracy. A Computer produces results without any error. A
repetitive calculation is performed with the same accuracy for any
number of times in a Computer. That is why Computers are used in
solving problems.
46) Give a formal definition for a program.
An assault on large problems employs a succession of programs. These
programs are rife with issues that appear to be particular to the problem at
hand.
47) Name the four paradigms of programming.
(i) Unstructured programming (ii).Structured programming and
(iii)Object Oriented programming (iv) Aspect Oriented programming
48) Mention the types of programming languages.
(i) Machine language
7

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN
CSEITQUESTIONS.BLOGSPOT.IN

(ii) Assembly language


(iii)High-level language
49) State the requirements for solving problem by computers.
To appreciate programming an as an intellectual activity in its own
right, we must turn to Computer programming. We must read and
write computer programs many of them.
50) Name the different aspects of problem solving.
It is widely recognised that problem-solving is a creative process
which largely defies systematization and mechanization. This may
not sound very encouraging to the would-be problem-solver. To
balance this, most people, during their schooling, acquire at least a
modest set of problem-solving skills which they may or may not be
aware of. Within this context, then, where can we begin to say
anything useful about computer problem-solving? We must start from
the premise that computer problem-solving is about understanding.
51) What are the primary strategies of problem solving?
(i) Understanding of the problem. (ii) Developing a design strategy.
(iii) Planning the development process.
52) Illustrate the idea behind the top-down-design approach.
Top-down design is a strategy that we can apply to take the solution
of a computer problem from a vague outline to a precisely defined
algorithm and program implementation. Top-down design provides
us with a way of handling the inherent logical complexity and detail
frequently encountered in computer algorithms. It allows us to build
our solutions to a problem in a stepwise fashion.
53) Mention the steps in bottom up design with an illustration.
In a bottom-up approach, the individual base elements of the system
are first specified in great detail. These elements are then linked
together to form larger subsystems, which then in turn are linked,
sometimes in many levels, until a complete top-level system is
formed. This strategy often resembles a "seed" model, whereby the
beginnings are small, but eventually grow in complexity and
completeness. Object-oriented programming (OOP) is a paradigm
that uses "objects" to design applications and computer programs.
Algorithm, Flowcharts and pseudocode
54) Define the term algorithm. List the characteristics of a good algorithm.
An algorithm is defined as a finite sequence of explicit instructions
8

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN
CSEITQUESTIONS.BLOGSPOT.IN

that, when provided with a set of input values, produces an output and
then terminates. An algorithm must have no ambiguity. There
should not be any uncertainty about the next instruction execution.
It should terminate in a finite number of steps.
55) What is meant by computational complexity of an algorithm?
It is the execution time of the algorithm in terms of its input parameters.
56) Explain the advantages of an algorithm.
A good algorithm helps the programmer to design the program in an
easier manner.
57) Define the term pseudo-code.
Pseudocode is not the actual name but it models and may even look like
programming code. It is the generic way of describing an algorithm
without using any programming language related notations. Or, more
simply it is the outline of the program, written in a form that can be
easily converted into real programming statements.
58) Give the advantages and limitations of flowchart.
Advantages: it makes the logic clear and visual. It communicates the
interconnection of the logical system. The problem can be well analysed.
Useful for coding the problem. Testing and debugging is easily done.
Flowcharts are good programming documentation for future reference.
Disadvantages: it is complicated. It is costly and difficult to modify in
future and no updates are easy to do.
59) Give the advantages and limitations of pseudocode.
Advantages: it is language independent. It is easier to develop
program from pseudocode than from flowchart. It is very compact
than a flowchart.
60)
What are the three basic program control
structures? Sequence, selection and repetition.

UNIT I BIG QUESTIONS


1) Explain the evolution of Computers

2) Explain the different computer generations.

3) Explain the classification of computer in detail.

4) With a block diagram explain computer organization.

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN

GE6151 COMPUTER PROGRAMMING


QUESTION BANK
5) Explain briefly about (a) Mainframe computers
(b) Super computers
6) Explain about the various characteristics of a Computer.

7) Explain the various types of computer memory.

8) Convert 6245.118 into its decimal equivalent

Perform the following subtraction: 68-47 and 47-68 in 1s and


2s complement method.
10) Illustrate the process of addition and subtraction in 1s and 2s
complement system with suitable examples
11) With examples illustrate the conversion of Decimal to Binary,
Octal and Hexadecimal numbers.
12) Convert 39.77 into binary.

12

13) Convert 1011.1101 to octal, hex and decimal.

14) Convert 1723.256 to Hex.

15) Add 39 & 93 using BCD addition method.

16) Explain in detail about (i) EBCDIC (ii) ASCII


(iii) UNICODE
17) Describe the basic steps in the system development life cycle.
18) What documentation should a programmer receive to be able
to write a program?
19) List and explain the steps that a programmer follows in
writing a program?
20) What are the three tools the programmer uses to develop a
program solution?
21) Define an algorithm. List the characteristics of a good
algorithm.
22) Draw a flow-chart to multiply two matrices.
23) Write a algorithm to multiply two matrices.

9)

10

8
8
4

5
6
5
3
6
8
8

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN

24) Write a pseudocode to multiply two matrices.

25) Write an algorithm to compute the factorial of a number


26) Define a flow-chart. List the advantages of using a flowchart.
27) Draw a flow-chart to find the highest of marks in a set of n
marks.
28) What are the advantages of using a pseudo-code?
29) Write a pseudo-code to add two matrices.
30) Discuss the three basic program control structures with
suitable examples.
31) Explain the features of a good programming language.
32) Describe the characteristics of programming languages.
33) Explain the top-down and the bottom-up approaches in
program development.
34) What are the advantages of structured programming?
35) What is the difference between black-box and white-box
testing?

8
5
8
5
8
6
8
8
8
6
8

UNIT II
Introduction to C programming fundamentals structure of a C
program
1) Why is C language called middle-level language?
C combines the features of high-level language and functionality like
assembly language. It reduces the gap between high-level language and
low-level language, that is why it is known as middle level language.
2) What are the functions of an interpreter and a compiler?
An interpreter reads only one line of the source program at a time and
converts into object codes. In case of errors, the same may be indicated
instantly. The compiler reads the entire program and converts it to the object
code. It provides errors not of one line but errors of entire program.
3) Write the rules for writing a C program.
a) All statements should be written in lower case. Upper case letters
are used only for symbolic constants.
b) Blank spaces may be inserted between words. This improves
the readability of the statements. But it is not used while
11

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN

declaring a variable, keyword and constant and functions.


c) It is not necessary to fix the position of statements in the program,
that is the programmer can write the statement anywhere between
the two braces following the declaration part. The user can also
write one or more statements in one line by separating a semicolon
(;) between them.
d) The opening and closing braces should be balanced.
4) Elaborate different sections of C program.
a. Include or header file section
b. Global declaration.
c. Function main.
d. Declaration section.
e. Executable part.
f. User-defined function.
g. Comments
5) What is the role of ( {}) curly braces in C program?
The program execution starts from the opening brace ({) and ends with
the closing brace (}). Between these two braces the program should
declare the declaration and executable part
6) What is meant by compilation? Explain in detail.
The source program statements should be translated to object programs
which is suitable for execution by the computer. The translation is done
after correcting every statement. If there is no error, the compilation
proceeds and translated program are stored in another file with same file
name with extension .obj. if any errors are there, the programmer should
correct them. Linking is also an essential process. It puts all other program
file and functions together that are required by the program.
7) Briefly explain the functions of a linker.
After the program has been translated into object code, it is ready to be
linked. This process is once again performed automatically whenever the
cc or gcc command is issued under Unix. The purpose of the linking
phase is to get the program into a final form for execution on the computer.
If the program uses other programs that were previously processed by the
compiler, then during this phase the programs are linked together. Programs
that are used from the systems program library are also searched and linked
together with the object program during this phase. These are the functions
of the linker.
8) What are the different standard data types?
12

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN

There are only four standard data type available in C.


char specifies a character variable
int specifies an integer variable
float specifies a floating-point variable
void associates function returning no value
9) What are the differences between signed and unsigned data types?
Signed integer
Unsigned integer
Signed integer occupies 2 bytes
in memory
Range : -32,768 to 32,767
Format specifier is %d or %i
By default signed int is short

Occupies 2 bytes in memory


Range : 0 to 65535
Format specifier is %u
By default unsigned int is

signed int
short unsigned int
Constants, Identifiers, variables and data types
10)
What is meant by a variable and a constant?
In a declaration, which consists of type, variable(one or more variables are
declared after the type, separated by commas) and delimited with a
semicolon. Moreover, during the type declaration, the variables so declared,
may be assigned with some corresponding values which has the following
format:
type variable = expression;
There are four basic types of constants in C. They are integer constants,
floating-point-constants, character-constants, and string-constants.
11) What are the C keywords? Elaborate them.
The following words are called reserved words or keywords and may not
be used by the user.
auto
double
int
struct
break
else
long
switch
case
enum
register
typedef
char
extern
return
union
const
float
short
unsigned
continue for
signed
void
default
goto
sizeof
volatile
do
if
static
while
13

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN

12)
List the rules for declaring a
variable. <Data-type> <variable-name>
13)
What are identifiers?
An identifier is a sequence of letters or digits that is, a..z or A..Z or 1..9.
The underscore is an identifier. Identifiers have 31 characters which are
significant and some time more characters are considered to be
significant. Internal identifiers are preprocessor macro names. An external
identifier starting with an underscore is reserved for the C library.
1. First character must be alphabetic character or underscore.
2. Must consist only of alphabetic characters, digits, or underscores.
3. First 31 characters of an identifier are significant.
4. It can not duplicate a reserved word(as described before)
14)
Explain the methods for initialization of variables.
variable-name = constant;
Or
<data-type> <variable-name> [= <constant>];
15)
Write about space requirement for variables of different data types.
Data type
char
unsigned char
int
unsigned int
long
float
double
16)

Size(byte)
1
1
2
2
4
4
8

What are delimiters? Explain their uses.

Language pattern of C uses special kind of symbols that are terminals in


nature, which are called delimiters.
Delimiters
Use
: colon
Useful for label
; semicolon
Terminates statement
( ) parenthesis
Used in expression and functions
[] square
Used in array declarations
brackets
14

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN

{} curly braces
Scope of statement
# hash
Pre-processor directive
, Comma
Variable separator
17)
List any three keywords with their use.
Operators and expression, Simple input and output functions
18)
What is the difference between %f and %g format specifiers? Can both
be used representing float numbers?
%f is decimal point format where as %g is a scientific format using exp
fields.
19) What do you mean by type conversion? Why is it necessary?
Implicit type conversion and Promotional hierarchy:
char short int unsigned int long int u
l int float double long double
So, when char and float are added, result will be a float. Similarly, if a
long is added with a double, the result will be a double according to the
promotional hierarchy, available.
Explicit type conversions
Cast. By having a unary operator called cast, we can convert the integer
to a float.
20) Explain different types of operators available in C.
Types of operator
Symbolic representation
Arithmetic operator
+, - , *, /, and %
Relational operator
>,<,==,>=,<=, and !=
Logical operator
&&, ||, and !
Increment and decrement
++ and -operators
Assignment operator
=
Bitwise operator
&, |, ^, >>,<<, and ~
Comma operator
,
Conditional oerator
?
21)

What are the uses of comma (, ) and conditional (?) operators?

The (,) comma operator is used to separate two or more expressions. The
comma operator has the lowest priority among all other operator is C.
Conditional operator (?) The conditional operator contains a condition
followed by two statement values. If the condition is true the first
statement is executed, otherwise the second statement. The syntax is as
15

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN

follows:
Condition ? (expression1):expression2);
22)
What are Unary operators and their uses?
+,-,++,--,!,~,*,&,sizeof and <type> are known to be
unary operators.
C includes a class for operators that act upon a single operand to produce a
new value. Such operators are called unary operators. Unary operators often
precede their single operands. The most common operation is unary minus,
where the numerical constant, variable or expression is preceded by a minus
sign. Note that the unary operator minus is distinctly different from the
arithmetic operator which denotes subtraction(-). The subtraction operator
obviously requires two separate operands.
23) Describe logical operators with their return values.
Operator
Meaning
&&
AND
||
OR
These are referred as logical AND and logical OR, respectively.
Suppose that i is an integer variable with value 3 and c is a character
variable with value 'w' and f is a floating point variable with value 3.56.
Several complex logical expressions that make use of these variables is
shown below.
Expression
Interpretation
Return
Value
(i <= 2) && (c > 34)
False
0
(c >= 56) | | (i == 4)
True
1
(c != 'x') && (f == 3.56)
true
1
The first expression is false because, the first operand is false. Where as in
the second expression, the second operand is false but the first operand
makes it effectively true. In the third expression, both the operands are
true.
24)

Distinguish between logical and bitwise operators.

Logical operators return either true or false where as bitwise operator returns
the result of the operation.
25)
What are relational operators?
There are four relational operators in C. They are
16

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN

Operator
Meaning
>=
greater than or equal to
> greater than
<=
less than or equal to

< less than


Closely associated with the relational operators, there are two equality
operators.
Operator
!=
26)

Meaning
= equal to
not equal to

What is the difference between '=' and '=='?

= is an assignment operator and the other one is an equality operator.


27)
What are the symbols used for a) OR b) AND c) XOR d) NOT
operations. OR - | |, AND - &&, XOR - ^, NOT - !
28)
Explain the precedence and associativity of operators in
arithmetic operations.
Precedence is used to determine the order in which different operators in a
complex expression are evaluated.
Associativity is used to determine the order in which operators with the same
precedence are evaluated in a complex expression.
29)
List the operators from higher priority to least
priority. Highest to the lowest
1
Primary
()
2
Postfix
( ), [ ],->, ++, -3
Unary
++,--, sizeof, +, -, &, *, ~,( )
4
Binary
*,%,/,+,-,<<,>>, <=,>=, ==,!=, &,^,|,&&,||
5
Ternary
?:
6
Assignment =, +=, -+, *=, /=, %=, >>=,<<=,&=,^=,|=
7
Comma
,
30)
What is the difference between division and modular division
operations? Modular division(%) returns the remainder after division
whereas division(/) returns the quotient after division in the case of integer
otherwise actual quotient in decimal points is returned
17

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN

Managing Input and Output operators


31) What

are the ASCII codes? List the codes for digits 1 to 9, A to Z and a to z.
1-49(decimal) ...9-57(decimal ASCII), A-65(decimal ASCII)...Z-90, a97(decimal) and z 122(decimal ASCII).
32)
What are the formatted and unformatted I/O functions?
printf(),scanf() known as formatted I/O functions and
getchar(),putchar(),gets(),puts() functions are known to be
unformatted I/O functions.
33)
What is the difference between character I/O and string I/O?
Character I/O: Consider the function getchar(). This function reads the
character type data from the standard input. It reads one character at a time
and till the user presses the enter key. Similarly in putchar()function, it
prints one character on the screen at a time, which is read by the standard
input.
String I/O: Consider the function gets( ). This
function is used for accepting any string through stdin(keyboard) until
enter key is pressed. The header file stdio.h is needed for
implementing the above function. Similarly puts() prints the string or
the character array.
34)
What are the escape sequences?
An escape sequence like \n provides a general and extensible mechanism for
representing hard-to-type or invisible characters. Theyre summarised in the
table below
Escape sequence
Character
\a
alert(bell)
\b
backspace
\f
formfeed
\n
newline
\r
carriage return
\t
horizontal tab
\v
vertical tab
\\
backslash
\?
question mark
\'
single quote
\"
double quote
\ooo
octal number
\xhh
hexadecimal number
18

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN

\0

null

35) Write a C program to print the following pattern:


0
1
2

0 1

1 0 1 2

Program
#include <stdio.h>
#include <conio.h>
main()
{
int a,b,c,d;
clrscr();
printf(%5d\n,0);
printf(%6d\n,101);
printf(%7d,21012);
getch();
}
Output
0
101
21012

Decision Making - Branching and Looping


36)
Is it possible to use multiple default statements in switch()
statement? No
37)
Write the use of else and default statements in if-else and
switch( ) statements respectively.
In the if-else structure which is known to be 2-way selection, takes care
of true as well as false conditions. It has two blocks one block is for if
statement and it is executed when the condition is true. The other block is for
else statement and it is executed when the condition is false.
In the switch( ) statements, the default is executed if none other
values of the case labels satisfy the value of the switch( ) constant.
19

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN

38)

Why goto statement is avoided?

It is learnt that the goto statement may let a programming language


abused. Since in practice, it is always possible and easy to write code
without goto statements, the goto statements are avoided in view of good
programming practice.
39)
Why break statement is essential in switch( ) statement? Which
other functions or keywords can be used in place of the break statement.
The break statement causes control to be transferred out of the switch
statement, thus preventing more than one group of statements from
being executed.
40)
Is it possible to use else statement in place of default or vice
versa? No
41)
Can we put default statement anywhere in the switch () case
structure? Yes. But as usual, the break statement is necessary to bypass to other case labels.
52)

What are the limitations of switch() case statement?

Every time when a case label matches, the corresponding case block
is executed. In the case-block a break statement is necessary to exit
the switch which is a limitation.
43)

What is a loop? Why it is necessary in the program?

The concept of a loop is to do an action repeatedly over and over again.


Generally the loop dont stop. We want our program to end when the work is
done. To make sure that the work is done, we have a condition that controls
the loop. We must design the loop in such a way that before and/or after each
iteration, it checks to see if it is done. If it is not, it repeats one more time.
The loops are classified as counter controlled and event controlled loops.
44)
What happens if you create a loop that never ends?
The program never terminates without any user intervention.
45)
Is it possible to create a for loop that is never executed?
Yes. If the pre-test condition is false, the loop is never executed.
46)

Is it possible to nest while loop within for


20

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN

loops? Yes
47)
What is the difference between (!0) and (!1)? How while loop works
with these values?
Actually !0 is 1 and !1 is a 0.
48)

What is the difference between (1= =!1) and (1!=1) ?

!1 evaluates to 0 so (1==!1) will become (1==0) which is false so, (1==!1)


evaluates to 0. Similarly, in the expression, (1!=1), both lhs and rhs of the !=
operator are the same. So the expression will evaluate to false and its value
would be 0. Though the return the same value of 0, they have different
evaluation sequence.
UNIT II Part B Questions
1) Explain the different types of operators available in C
2) What are constants? Explain the various types of constants available
in C
3) Mention the use of break and continue statements
4) Explain the program control structures with examples.
5) What is meant by operator precedence? Discuss its impact in
programming with suitable examples.
6) Explain how switch statement differ from if statement.
7) Write a C program to print the given number in reverse.
8) Explain any two constructs used for decision making, branching and
looping statement. Give an example and explain the working of the
construct.
9) Write a C program to evaluate the following series

10) Write a program in C to check if the given number is prime.


11) Write a C program to check whether the given number is palindrome
or not.

12) Write a C program t generate Fibonacci series upto 200.


13) Write a program in C to represent the number of years represented by
21

8
8
4
6
8
5
6
16

8
8

8
16

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN

an integer into the following units of time:


a) Minutes
b) Hours
c) Days
d) Months
e) Seconds.
Use switch( ) statement. State the assumption made in your problem.
14) Write the syntax of for construct in C with suitable examples.
4
15) Write a C program to determine the number of and sum of all integers 8
between 100 and 200 which are divisible by 7.
UNIT III
Part A Questions and answers
Arrays Initialization, Declaration, One dimensional and Two
dimensional arrays
1) Mention the advantages and limitations of arrays
Advantages: while analysing a huge size of data, all of them will not be of
sequence or integers. So indexing these data will help processing better
and this idea can be extended to multi-dimension. Disadvantages: The
memory size for an array can not be altered after compile time(they are
static in nature) so expanding or contracting the
array size at run time is a big problem in limiting the size of the program. So
by considering the worst cases only the size of the array is decided so
flexibility of program-size with respect to small and big amount of data is
not possible in C.
2) What is the relation between an array name and an element number?
How are elements referred using base addresses?
Let us consider the following program segment:
int a[5]={1,2,3,4,5};
printf(Base address=%u

and

its

printf(second address=%u and its


printf(fifth position address=%u

value=%d\n,a,a[0]);

value=%d\n,a+1,a[1]);
value=%d\n,a+4,a[4]);

here, first printf will correspond to printing the base address of the array
under consideration and its value which is 1.

22

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN
CSEITQUESTIONS.BLOGSPOT.IN

GE6151 COMPUTER PROGRAMMING


QUESTION BANK
Output:
Base address=2345624 and its
value=1 second address=2345628 and
its value=2
fifth position address=2345640 and its value=5
The elements can be referred using a dereferencing operator *. That is
*(a+1) is the content of the address of a+1 which corresponds to the
second array position.
3) An array name contains base address of the array. Can we
change the base address of the array?
No. it is done by the compiler usually at runtime.
4) Can we store values and addresses in the same array? Explain.
No. Here the value at an array address may not accommodate a
pointer. Probably if we have an array of pointers we can do that.
5) Mention the difference between character array and integer array.
Character array
Integer array
Each array position occupies
single byte.

It occupies two bytes

A special case of a character array No such cases exist


is called a string which is
terminated by a \0 character
6) How does an ordinary variable differ from an array definition?
An ordinary variable will have one value corresponding to it. But an
array can have different values assigned at various positions of its
index
7) Give the syntax of declaring a two-dimensional array.
storage-class <data-type> arrayname[expression1][expression2];

Storage-class is an optional field. Every arrayname associates


with a data-type. expression1 and expression2 are positive
valued integer expressions.
23

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN
CSEITQUESTIONS.BLOGSPOT.IN

8) Explain multi dimensional array.


The C program allows array of two or multi dimensions. The compiler
determines the restriction on it. The syntax of multi-dimensional array
is as
follows. arrayname [S1][ S2][ S3]...[ Sn]; where, Si is the size
of the ith dimension. Few examples are, int mat[ 3][ 3]; int
marks [3][3];
A linear indexing formula for multi-dimensional arrays that are
declared as such, e.g. by int A[10][20] or int A[m][n]
Strings- String operations String Arrays
9) What are strings? How are they declared?
Character arrays terminated by \0 are called strings.
Strings are normally used to manipulate the text such as
words and sentences. For example
char name[ ] = INDIA;
10)
What is NULL character? Why is it important?
The NULL character \0 is the terminal character in a string array.
11)
Is it possible to initialize NULL character in the string?
The last character in a string array is the NULL character so if the
last character in a character array is not a NULL character and if it
is initialised with a NULL character then that character array will
become a string array.

24

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN
CSEITQUESTIONS.BLOGSPOT.IN

12)

Mention some standard string functions available in C.


char*strcat(s,ct)

concatenates source string ct to end of s


returns s.

size_t strlen(cs)

Determines the length of a string

Copy string ct to string s return s. Pad


with '0' if ct has fewer than n characters
compare string cs to string ct,
int strcmp(cs, ct)
return <0 if cs<ct, 0 if
cs==ct, or >0 if cs>ct.
In the above table, variables s and t are of type char *; cs and ct
are of type const char *; n is of type size_t; and c is an int
converted to char.
13)
Why is it necessary to count NULL character while declaring
string?
char *strcpy(s,ct)

Because the total count determines the number of array indices


used to store the particular string.
14)
What is the difference between the functions
strcmp( ) and strncmp()?
strncmp(s,t,n) is the same as strcmp(s,t)
compares only the first n characters.
15)
What is the difference between NULL, '\0' and 0?

but it

\0 is the escape sequence in the format specification. 0 is the


corresponding ASCII code for the NULL character. NULL is the name
in which it is interpreted in English in reference to C language.
Sorting Searching and Matrix Operations
16)
Name the different sorting techniques available.
Shell sort, quick sort, insertion sort, radix sort and bubble sort.
17)
Give the algorithm for bubble-sort
Let a[0],a[1],...,a[n-1] be an array declared and initialised in C.
The bubble-sort algorithm can be shown as below:
1 for i = 0 to n-1
2 for j= n-1 downto i + 1
3
if a[j] < a[j - 1]
25

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN
CSEITQUESTIONS.BLOGSPOT.IN

exchange a[j]

with

a[j-1]

Line 3 in the above algorithm will execute n-1 number of times and in
the first loop and n-2 times in the second loop and so on. Thus, totally
the comparison(line 3) will occur
(n-1)+(n-2)+(n-3)+...+3+2+1 =
times.
18)

Mention the need for searching program with an example.

In many situations there is requirement of finding a particular


data/element among a large collection of data. So there must be some
method to locate whether or not the desired data is present in a list at
shortest time becomes important. Search algorithms are designed for
such purposes. Example: voter information.
19)
Distinguish between linear search and binary search.
Linear search is done on an unordered list where as the binary
search is done on an ordered list. Binary search is more efficient.
20)
Mention the advantages of quick sort over selection sort.
The quick sort is supposed to perform better than selection sort in a
large
run.
Unit III Part B Questions
1) Explain the need for array variables. With respect to arrays, describe 8
the following: declaration of arrays, Two-dimensional array and
accessing an array element.
2) Write a C program to add and subtract two matrices.

3) Explain the need for array variables. With respect to arrays, describe 8
the following: declaration of arrays, Two-dimensional array and
accessing an array element
4) Write a C program to find the largest and the smallest number in a
given array
5) Write a program that calculates the average of an array of 10
floating- 5 point values.
6) Write a C program to sort a given set of numbers in ascending order.
8
26

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN
CSEITQUESTIONS.BLOGSPOT.IN

7) Write a C program to count letters in a sequence of characters

8) Discuss about any eight built-in string/other library functions

UNIT IV
Part A Questions and answers
Function definition of function Declaration of function, pass by
value, pass by reference
1) Write the definition of a function. Indicate the types of
functions available in C.
data-type name(type-1 arg-1, type-2 arg-2, , type-n arg-n)

where data-type represents the data type of the item that


is returned by the function, name represents the function name,
and type-1, type-2 type-n represent the data type of the
arg-1, arg-2,, arg-n respectively. The data types are
assumed to be of type int if they are not shown explicitly.
However the omission of the data types is considered poor
programming practice, even if the data items are integers.
2) How do functions help to reduce the program size?
There are several advantages to modular approach to program
development. For example, many programs require that a
particular group of instruction be accessed repeatedly from several
different places within the program. The repeated instruction can
be placed within a single function, which can then be accessed or
whenever it is needed. Moreover a different set of data can be
transferred to the function each time it is accessed. Thus, the use
of a function is to avoid the need of redundant(repeated)
programming of the same instruction.
3) Differentiate between library and the user-defined functions
Library functions
User defined functions
These are predefined set of
functions

Defined by the user according


to requirement

The task is limited

The user understands the


scope of the function so that
the ideas may be implemented
27

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN
CSEITQUESTIONS.BLOGSPOT.IN

in the best way.


4) How does a function work? Explain how arguments are
passed and results are returned?

Once a function is defined and called, it takes some data from the
calling function and returns a value to the called function.
The detail of inner working of function is unknown to the rest of
the program. Whenever a function is called, control passes to the
called function and the working of the calling function is stopped.
When the execution of the called function is completed, control
returns back to the calling function and executes the next
statement.
The values of the actual arguments passed by the calling function
are received by the formal arguments of the called function. The
number and type of the actual and formal arguments must be the
same. Any mismatch will produce unexpected result.
The function operates on formal arguments and sends back the
result to the calling function. The return() statement performs this
task.
5) List any five-library functions and illustrate them with suitable
examples.
float pow(float,float);

The above is the proto type for power function where the first
y
argument is raised to second power. That is x where x is first and
y is second argument.
z = pow(4.0,5.0);

Will cause z to have 1024.0 assigned. In other words, the


above statement returns the value 1024.0 to the calling
module.
//void strcat(char *,char
*); char x=abc,y=def;
printf(%s,strcat(x,y));

will cause abcdef to be printed on the screen.


6) What are actual and formal arguments?
Actual arguments are the parameters of the calling module.
Formal arguments are the parameters of the called module.
7) What is the purpose of return () statement?
28

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN
CSEITQUESTIONS.BLOGSPOT.IN

This helps function in sending back the results to the calling module.
8) What does it mean if there is no return statement in the function?
Functions without return statement is not wrong if the function
return a void type otherwise, an error message will be displayed by
the compiler.
9) What are void functions?
They return no value to the calling module.

10)
Why is it possible to use the same variable names for actual
and formal arguments?
In the called module however new local variables are created
every time a function is called(except the function has reference
parameters)
11)
What is main () function in C? Why is it necessary in
each program? This is what is first invoked by the compiler to
further proceed.
12)
Explain the different formats of return ( ) statements. How
many values does return statement return at each call?
The return statement can be used in the following ways:
1. return(expression); Here expression value is returned
to the calling function and if expression is omitted return simply
transfers control to the calling function. 2. There may be one or
two return statements in a function. They may be executed
according to the condition arising in a program.
13)
What is a global pointer? Illustrate with a suitable example.
Normally pointers addresses declared outside a function are referred
as global pointers with respect to the called functions. Consider:
main(){
int a=3,b=4;
swap(&a,&b); printf(a=
%d b=%d,a,b);
}
void
swap(int
*m,int
*n){ int temp;
temp =
*m; *m =
*n; *n =
temp;
}
29

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN
CSEITQUESTIONS.BLOGSPOT.IN

In the above code snippet, the function swap has an argument which
is of type pointer to an integer, passed on to the function which is
global with respect to the function swap.
14)
Why is return statement not necessary when function is
called by reference?
The reference parameters are transparent to the calling module so
the changes made by the function will automatically become visible
to the calling module upon a successful return of the called
function.
15)
Distinguish between function prototype and function
definition(code)?
Function prototype is the function declaration where as the function
definition is the actual content of the function statements return
values etc..
16)
Does the function prototype match with the function
definition? Yes.
17)
Can we define a user-defined function with the same library
function name?
No; but if the header file is not included for the particular program,
the function name will not conflict so it is allowed only in such
occasion.
18)
List and explain the four scope of variables in brief.
Automatic variables(local variables), External variables,
Staticvariables
and Register variables
19)
What are automatic/local variables?
These are defined inside a function. A variable declared inside a function
without a storage class name, by default is an auto variable. The scope of
the variable is local to the block in which they are defined. These
variables are available only to the current block or program. Once the
execution of the function takes place and return turns off function, the
contents and the existence of the auto variables or local variables vanish.
20)
Distinguish between static and external variables?
Static variable
External variable

The static may be of internal


or external type, depending
30

External variables are


declared outside the function

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN
CSEITQUESTIONS.BLOGSPOT.IN

upon where it is declared

body.

It is initialised only once.

If both external and auto


variables are declared with
the same name in a program,
the first priority is given to
auto variable.

The value of static variable


persists on each call and the
last change made remains
throughout the program
execution.
21)
Can we declare a variable in different scopes with different
data types? Answer in detail
22)
What is calling by reference in C?
In this method, the addresses of the actual arguments are passed to
the formal parameters of the function.
23)
Give an example for a function returning a pointer
The following function gets an integer between 1 and 12 and returns
the pointer to month name.
/* month_name: return name of n-th month
*/ char *month_name(int n)
{

static char *name[]


= { "Illegal
month",
"January", "February",
"March", "April", "May",
"June",
"July", "August", "September",
"October", "November",
"December"
return(n < 1 || n > 12)?name[0]:name[n];

In the above function the variable name is a static array of character


pointers. The initializer is a list of character strings; each is assigned
to the corresponding position in the array. The characters of the i-th
31

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN
CSEITQUESTIONS.BLOGSPOT.IN

string are placed somewhere, and a pointer to them is stored in


name[i]. Since the size of the array name is not specified, the
compiler counts the initializers and fills in the correct number
Pointers definition, initialization
24)
What are pointers? Why are they important?

25)

Other language have pointers but few uses them so freely, with
such abandon, as C does. And why not? It's C's clever use of
pointers that makes it the excellent systems language.
Explain the use of (*) indirection operator.
(*)s operand is the address of a value stored in memory, and it
returns the value stored in that address.
The example below shows that:
void main()
{
int alpha = 1;
printf("The value %d is stored at address%u.\n",alpha,&alpha);
printf("The value %d is stored at address
%u.\n",*(&alpha),&alpha);

the output is
The value 1 is stored at address
9364. The value 1 is stored at
address 9364. after execution.

The expression alpha - that is, the name alpha by itself - and the
expression *(&alpha) do exactly the same thing: both cause C to
return the value stored at the address associated with the name alpha.
The expression &alpha returns alpha's address, and *(&alpha)
returns the value stored at that address.
26)
Explain the effect of ++ and -- operator with pointer of all
data types. Consider the following program
#include
<stdio.h> void
main ()
{
float *ptr;
static float zilch[] =
{1.23,2.34,3.45,4.56,5.67,0.0}; ptr = zilch;
32

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN
CSEITQUESTIONS.BLOGSPOT.IN

while (*ptr != 0.0)


{
printf("The value stored at address %u is %f\n",ptr,*ptr);

ptr++;
}
}
The output would be
The value stored at address 4144 is
1.230000 The value stored at address 4148
is 2.340000 The value stored at address
4152 is 3.450000 The value stored at
address 4156 is 4.560000 The value stored
at address 4160 is 5.670000
Note the intervals between the address now. They are each 4. Our
references computer addresses its memory byte by byte, and an int
takes up two bytes where as a float uses four. The same case applies
to
operator as well.
27)
Explain the relation between an array and
a pointer. Consider the declarion:
int prime[4]={2,3,5,7},*ap;
Here prime[0] refers to 2 prime[1] refers to 3 and so on. But simply,
prime will mean a pointer to the number 2 in the above declaration.
By having an assignment as
ap = prime;
will initialise the pointer variable ap to point to the first position of
the array we have just declared and initialised above. Also a
statement like
ap++;
will increment the value of the pointer variable ap to point to the
next position of the array that is prime[1]. This is the
relationship between array and a pointer.
28)
Which are the possible arithmetic operations with
pointers? int array[5]; /* Declares 5 contiguous
integers */ int *ptr = array; /* Arrays can be
33

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN
CSEITQUESTIONS.BLOGSPOT.IN

used as pointers */

ptr[0] = 1; /* Pointers can be indexed with array syntax */


*(array + 1) = 2; /* Arrays can be dereferenced with
pointer */ *(1 + array) = 3; /* Pointer addition is
commutative */ 2[array] = 4; /* Subscript operator is
commutative */
This allocates a block of five integers and names the block array,
which acts as a pointer to the block.
Unit IV Part B Questions
1) Write a C program using user defined function to sort numbers in
ascending order.
2) Write note on storage classes in C.
3) How can a function return a pointer to its calling function?
4) Explain in detail how an array can be passed as an argument in a
user defined function. Illustrate your answer with an example
program.
5) What are the advantages of using pointers? How are pointers
declared and initialised? How the value of the variable is accessed
using pointers? Give examples.
6) Give an example of a C function which can swap two integer
variables on a return.
7) Write a C program to copy one string to another and count the
number of characters copied.
8) Write an algorithm and a C program to print prime numbers lesser
than 500.

1)What is a structure in C? How is a structure declared?


A structure is a collection of one or more variables, possibly of different
types, grouped together under a single name for convenient handling.
Structures help to organize complicated data, particularly in large
programs, because they permit a group of related variables to be treated as
a unit instead of as separate entities.
34

6
6
6
8

8
8
10

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN
CSEITQUESTIONS.BLOGSPOT.IN

struct

tag{ Memb
er1;
Member 2;
...
Member m;

};
In this declaration struct is a required keyword; tag is the name that
identifies this type; member 1, member 2 ... member m are
individual member declarations.
2)How are structure elements stored in memory?
Consider the declaration shown next page:
struct student
{
char name[30];
int rollno;
float height;
};

35

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN

GE6151 COMPUTER PROGRAMMING


QUESTION BANK
studnt1

name[30]

rollno

height
struct studnt1 student;
The above declaration creates variables studnt1 of structure type student
and it reserves a total of 36 bytes(30 for the name[30], 2 bytes for the
rollno which is an integer and 4 bytes for float height)
3)Explain nested structure.
We can take any data type for declaring structure members like int, float,
char, and so on. In the same way, we can also take object of one structure as
members in another structure. Thus, structure within structure can be used to
create complex data applications. See below struct date
{
int dd; int mm;
int yyyy;
};
struct employee
{
char name[30]; struct
dob date; struct doj
date;
};
struct cseemp employee;
The above example shows how structure within structure is declared and it
36

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN

can be visualised as follows:


cse_emp
name[30]

dob
dd
mm
yyyy
doj
dd
mm
yyyy
4)What are aggregate types?
The structure is a kind of aggregate data type in C which is nothing but a
derived data type.
5) Can a structure have a pointer to itself?
Consider the following declaration for a node in a binary tree. Let us say the
node has a value which is of type integer and as it is a binary tree a node may
have two pointers pointing to two other nodes. This can be represented as:
struct *node
{
int value;
struct node *child1,*child2;
}
6) How is the declaration struct type{...}; different from typedef struct {...};?
By using typedef we can create new data type. The statement typedef
is to be used while defining the new data type. The syntax is as given below:
typedef type dataname;
37

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN

Here, type is the data type and dataname is the user-defined name for
that type.
typedef int hours;
Here, hours is another name for int and now we can use hours instead of int
in the declaration as given below:
typedef int hours;
hours hrs;
7)How to keep track of which field of a union is in use?
In C it is not possible to know what type is currently stored in union.
8)What are the differences between a symbolic constant and an enumeration
constant?
enumeration constant
symbolic constant
Enumerations are unique types that
A #define line defines a
have integral values; associated with
symbolic name or symbolic
each enumeration is a set of named
constant to be a particular string
constants. Enumerations behave like
of characters:
#define name replacement list
integers, but it is common for a
compiler to issue a warning when an
object of a particular enumeration is
Example:
#define MAX 100
assigned something other than one
of its constants, or an expression of
its type.
Example:
enum months {JAN=1, FEB,
MAR, APR, MAY, JUN, JUL, AUG,
SEP, OCT, NOV, DEC};
Now the value of MAY would be 5 but
if we say
enum months {JAN, FEB, MAR,
APR=100, MAY, JUN, JUL,
AUG, SEP, OCT, NOV, DEC};
the value of MAY would be 101 but the
value of JAN would be 0
9)What are the various stages a program undergoes before xecution?

38

CSEITQUESTIONS.BLOGSPOT.IN CSEITQUESTIONS.BLOGSPOT.IN
CSEITQUESTIONS.BLOGSPOT.IN

The various stages a program undergoes before execution are:


1.Translation 2.Loading
The various parts of translation are:
1.Preprocessing 2.Compilation 3.Linking
Source Program
Preprocessor
Simplified C Program
Source Libraries
(.obj Files)
Linker

Compiler
Object Code(.obj File)

Translation

Relocatable executable
Code (.exe File)
Loader
Address binding and
execution

39

Loading

10)What is a macro? What are object like macros and function like macros?
Preprocessor directives such as # define are used at the beginning of the C
program to define constants or any macro substitution.
#define <identifier> <replacement token list>
// The above one is an object-like macro
#define <identifier>(<parameter list>) <replacement token list>

// The above is a function-like macro, note parameters


The function-like macro declaration must not have any whitespace
between the identifier and the first, opening, parenthesis. If whitespace is
present, the macro will be interpreted as object-like with everything
starting from the first parenthesis added to the token list.
11)What is the role of the error directive?
#error "Pl. specify build type in the Makefile"
When the preprocessor hits the #error directive, it will report the string
as an error message and halt compilation; what exactly the error message
looks like depends on the compiler.
12)What is the role of the pragma directive?
The #pragma directive is the method specified by the C standard for
providing additional information to the compiler, beyond what is
conveyed in the language itself. An unrecognised pragma is ignored by
the compiler.
UNIT V Big Questions
1) What is a structure? How does a structure differ from an array?
6
2) How an array of structure is initialised?
6
3) How a structure member is accessed?
6
4) Explain about structures and unions with suitable examples.
6
5) Write short notes on Pre-processor directives
6
6) Define a structure with tag population with fields Men and
8
Women. Create structure within structure using state and
population structure. Read and display the data.
7) Write a C program to define structure with tag state, with fields
8
state name, number of districts and total population. Read and
display the data.
8) Write a C program to accept records of 20 states using array of
16
structures. The structure should contain name of the state and
number of engineering colleges, medical colleges, management
colleges, science colleges. Calculate and display the total colleges
in each state which is having the highest number of colleges

Vous aimerez peut-être aussi