programming in c quan book

124
FACULTY OF COMPUTER SCIENCE Programming in C Descriptive Questions Q-1 Write a note on History of C OR C is not a specific Language but is a general purpose language. Appreciate the sentence. OR The next version of C will be P and not the. D. Evaluate the statement. By 1960, number of computer languages had come into existence, almost each for a specific purpose. At this stage, people started thinking for a general purpose language. Therefore an international committee was formed to develop such a language. To reduce the abstractness and generality, a new language called CPL (Combined Programming Language) was developed at Cambridge. However, it turned to be so big, having so many features that it was hard to earn and difficult to implement. Basic Combined Programming Language (BCPL) was developed by Martin Richards to solve the problem by bringing CPL down to its good features. Meanwhile, Ken Thompson has developed language B as a further simplification of CPL. Dennis Ritchie inherited the features of B and BCPl in C, added some of his own and developed the language C. SHRI SUNSHINE GROUP OF INSTITUTIONS

Upload: ratish-kakkad

Post on 12-Nov-2014

1.969 views

Category:

Documents


3 download

DESCRIPTION

Programming in C - Question Answer Book for Long Questions, Short Questions, Multiple Choice etc.

TRANSCRIPT

Page 1: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

Programming in C

Descriptive Questions

Q-1 Write a note on History of C

OR

C is not a specific Language but is a general purpose language. Appreciate

the sentence.

OR

The next version of C will be P and not the. D. Evaluate the statement.

By 1960, number of computer languages had come into existence, almost each for

a specific purpose. At this stage, people started thinking for a general purpose

language. Therefore an international committee was formed to develop such a

language. To reduce the abstractness and generality, a new language called CPL

(Combined Programming Language) was developed at Cambridge. However, it

turned to be so big, having so many features that it was hard to earn and difficult

to implement.

Basic Combined Programming Language (BCPL) was developed by Martin

Richards to solve the problem by bringing CPL down to its good features.

Meanwhile, Ken Thompson has developed language B as a further simplification

of CPL.

Dennis Ritchie inherited the features of B and BCPl in C, added some of his own

and developed the language C. Dennis Ritchie's main achievement is the

restoration of lost generality and still keeping it powerful.

Various stages in evolution of C is as follows:

Year Language Developed by Remarks

1960 ALGOL Int. Committee Too general, too abstract

1963 CPL Cambridge Uni. Hard to learn, difficult to implement

1967 BCPL Martin Richards Could deal with only specific problems

1970 B Ken Thompson Could deal with only specific problems

1972 C Dennis Ritchie Loss generality of BCPL and B restored.

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 2: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

Q-2 Explain the features of C

OR

Which features have made C so popular?

The three important aspects of any language are the way it stores data, how it

accomplishes input and output and the operators it uses to transform and combine

data plays a vital role in making the language popular.

The increasing popularity of C is probably due to its many desirable qualities. It is

a robust language whose rich set of built-in functions and operators can be used to

write any complex program. The C compiler combines the capabilities of an

assembly language with the features of a high level language and therefore it is

well suited for writing both system software and business packages.

Programs written in c are efficient and fast. This is due to its variety of data types

and powerful operators. It is many times faster than BASIC.

There are only 32 keywords and its strength lies in its built-in-functions. Several

standard functions are available which can be used for developing functions.

C is highly portalbe. The C programs written for one computer can be run on

another with little or no change/modification.

Q.3 Write a note on C Character Set

A character denotes any alphabet, digit or special symbol used to represent

information. Following table shows the valid alphabets, digits, and special

symbols allowed in C.

Alphabets A to Z, a to z

Digits 0 to 90

Special Symbols {}() [] <> + = - / \ @ # etc.

Q.4 Write a note on structure of a C Program.

A C program can be viewed as a group of building blocks called functions. A

function is a subroutine that may include one or more statements designed to

perfroma specific task. A C program may contain one or more sections as referred

hereinbelow.

Documentation Section

Link Section

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 3: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

Definition Section

Global Declaration Section

Main() function Section

{

Declaration Part

Executable Part

}

Subprogram Section

{

Function-1 User-Defined functions

Function-2

Function-n

}

The documentation section consists of a set of comment lines giving the name of

the program, the author details which the programmer would like to use later. The

link section provides instructions to the compiler to lin functions from the system

library.

The definition section defines all symbolic constants. Some variables are used in

more than one function. Such variables are called global variables and are

declared in the global declaration section that is outside of all the functions.

Every C program must have one main function. This section contains two parts,

declaration part and execution part. The declaration part declares all the variables

used in executable part. There is at least one statement in the executable part.

These two parts must appear between the opening and closing braces. The

program execution begins at the opening braces and ends at closing brace. The

closing brace of the main function section is the logical end of the program.

Q-5 Describe four basic data types.

The constants and variables used in a C program should be casted / declared in it

before using them for execution. C language is rich in its data types. Storage

representations and machine instructions to handle constants differ from machine

to machine. All compiles support four fundamental data types namely integer

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 4: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

(int), character (char), floating point (float) and double precision floating

point(double).

The integers are the whole numbers with a range of values supported by a

particular machine. Generally integers occupy one word of storage. The Floating

point numbers are stored in 32 bits with 6 digits of precision. Floating point

numbers are defined in C by the keyword float. When the accuracy provided by a

float number is not sufficient, the double data type should be used to define the

number. A double data type member uses 64 bits giving a precision of 14 digits.

A single character can be defined as a character data type. Characters are usually

stored in 8 bits (one byte) of internal storage.

Q.6 Write a note on C Tokens.

In C program smallest individual units are known as C Tokens. C has six types of

tokens namely Keywords, Identifiers, Constants, Strings, Special Symbol and

Operators.

Every C word is classified as either a keyword or an identifier. All keywords are

pre-defined words with pre-defined meaning and serve as basic building blocks

for program statements. Identifiers refer to the names of variables, functions and

arrays. These are the user defined names which consist of a sequence of letters

and digits with a letter as a first character. Both uppercase and lowercase

characters are permitted. Constants in C refer values that do not change during the

execution of a program. C supports basically Integer Constants, Real Constants

and Character Constants.

Q.7 Write a note or C Constants

Constants in C refer to fixed values that do not change during the execution of a

program. C supports basically Integer Constants, Real Constants and Character

Constants. An Integer constant refers to a sequence of digits. There are three

types of integers namely decimal, octal and hexadecimal. The numbers

containing fractional part are called real or floating pointconstants. These

numbers are shown in decimal notation, having a whole number followed by a

decimal point and the fractional part. A real number may also be expressed in

exponential notation. The general form of scientific notation is

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 5: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

Mintissa e exponent

Whereas the mintissa is a real number expressed in decimal notation or an integer.

The exponent is an integer number with an optional plus or minus sign.

A Character constant contains a single character enclosed within a pair of single

quoted marks.

Q-8. Explain the rules for naming a variable.

In C, a quantity, which may vary during execution of the program, is called a

variable. The rules framed by C language for constructing variable names can be

listed as follows:

(a) A variable name is any combination of 1 to 8 alphabets, digits or numbers.

Some compilers allow variable names whose length could be upto 40

characters. Still it would be safer to stick to the rule of 8 characters.

(b) The first character in the variable name must be an alphabet.

(c) No commas or blanks are allowed within a variable name.

(d) No special symbol other than an underscore can be used in a variable. The

above-referred rules remain same for all types of variables, i.e. integer

variables, real variables and character variables.

Q-9. Discuss the hierarchy of operators.

The order or priority or the precedence in which the arithmetic operations are

performed in an arithmetic statement is called as the hierarchy of operations. The

hierarch of operations while evaluating any Arithmetic instruction in C can be

narrated as follows:

Priority Operators

1st Parentheses- All parentheses are evaluated first.

Note: C allows only parentheses, i.e.(&) and not {} or [].

2nd Multiplication and Division- All multiplications and divisions are

performed next.

3rd Addition and Subtraction - These operations are performed last.

Q-10 What is a variable? How to declare it ?

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 6: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

A variable is a user-defined identifier [other than keywords] used in a C program

to store a value of any data and the value of which can be changed during the

execution of program.

A variable can be used to store a value of any data type. That is, the name has

nothing to do with its type. The syntax of declaring variable is as follows:

Data-type variable1, variable2, …… variable-n;

variable1, variable2 are the names of variables separated by commas. A

declaration statement must end with a semicolon. For example:

int no;

char name;

double percentage;

Here, int, char and double are the keywords to represent integer type, character

type and real type data respectively.

Q.11 What is escape sequence? Explain.

OR

Discuss the %[Conversion character] codes and backslash codes and their

uses.

C Language recognises the following escape sequences. When used with output

function like print( ), putcs( ), putchar( ) etc. the escape sequence help in

formatting output.

Escape Sequence Meaning

\n Newline

\t Tab

\b backspace

\r Carriage return/enter

\a Alert

\f form feed

\\ backslash

\- single quote

\" double quote

Q-12 What is user-defined type declaration ?

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 7: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

OR

What is similar in typedef and enum function ? Explain.

C supports a feature known as type definition that allows user to define an

identifier that would represent an existing data type. The user-defined data type

identifier can later be used to declre variables. The general form is as under:

Typedef type identifier;

Where type refers to an existing data type and identifier refers to the new name

given to the data type. The existing data type may belong to any class or type

including the user-defined ones. Typedef function cannot crate a new data type.

Some examples of type definition are as under:

Typedef int rno;

Typedef float marks ;

Typedef char name;

Another user defined data type supported by ANSI C is enum, i.e. Enumerated

Data-Type. The general form of enum is as under:

enum identifier {value1, value2,…. valuent}

The identifier is a user-defiend enumerated data type which can be used to define

variables which can have one of the values enclosed within the braces, popularly

known an enumeration constants.

Q-13 Write a note on Storage Classes in C.

Variables in C can have not only data type but also storage class that provides

information about their location and versatility. The storage class decides the

portion of the program within which the variables are recognized.

C provides a variety of storage class specifiers that can be used to declare

explicitely the scope and lifetime of the variables. The concepts of scope and

lifetime are important only in multifunction and multifile programs and therefore

the storage classes are considered in detail later when functions are discussed.

Storage class Meaning

auto Local variables known to only to the function in which it is

declared. Default is auto.

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 8: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

static Local variables which exists and retains its value even after the

control is transferred to the calling function.

extern Global variables known to all functions in the file.

register Local variable which is stored in the register.

The storage class is another qualifier that can be added to the variable

declaration as under:

auto int rollno;

register char name;

static int marks;

extern long total;

Static and external variables are automatically initialised to zero. Automatic

variables containes garbage, i.e. underfined values unless they are initialised

specifically.

Q-14. Write a note on operators.

C Supports a rich set of operators. An operator is a symbol that tells the computer

to perform certain mathematical or logical manipulations. Operators are used in

programs to manipulate data and variables. They usually form a part of the

mathematical or logical expressions.

Coperators can be classified into eight categories. They include:

(1) Arithmatic (2) Relational

(3) Logical (4) Assignment

(5) Increment and Decrement (6) Conditional

(7) Bitwise (8) Special

Q-15 Explain in brief:

(a) Arithmetic Operators (b) Relational Operators

(c) Logical Operators (d) Assignment Operators

(e) Increment and Decrement Operators

(a) Arithmetic Operators

C provides all basic arithmetic operators. The operators +, -, * and / all work in

the same way as they do in other language. These operators can operate on any

data type allowed in C.

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 9: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

Operator Meaning

+ Additional or unary plus

- Substraction or unary minus

* Multiplication

/ Division

% Modulo Division

The modulo division produces the remainder of an integer division. C does not

have any operator for exponentiation.

(b) Relational Operators

An expression containing relational operator is termed as a relational expression.

The value of a relational expression is either one or zero. C supports six relational

operators in all.

Operators Meaning

< is less than

<= is less than or equal to

> is greater than

>= is greater than or equal to

== is equal to

!= is not equal to

For example:

a < b or 1 < 20

Wherein a and b are the arithmetic expressions which may be simple constants or

variables or combination of them.

(C) Logical Operators

In addition to relational operators, C has the following three logical operators.

Operators Meaning

&& logical AND

!! logical OR

! logical NOT

The logical operators && and !! are used when we want to test more than one

condition and make decisions.

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 10: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

Some examples of the usage of logical expressions are :

1. if(age>55 && salary < 1000)

2. if(number<0 !! number > 100)

(d) Assignment Operators

Assignment operators are used to assign the result of an expression to a variable.

We have seen the usual assignment operator '='. In addition, C has a set of

shorthand assignment operators.

(e) Increment and Decrement Operators

C has two very useful operators not generally found in other languages. These are

the increment and Decrement Operators. The operator ++ adds 1 to the operand

while -- decreases 1. If the ++ sign is before the operand, it is called as

preincrement because it adds 1 before the evaluation of expression while ++ sign

after operand increases 1 after the evaluation of expression while ++ sign after

operand increases 1 after the evaluation of expression and therefore it is known as

post increment. The rule of pre and post increment applies to the pre and post

decrement even.

Q-16 Write a note on following :

(a) scant()

scant() is used to input data through input stream like keyboard and files. This

function stops program execution until a value is typed in and the return key is

pressed.

The general format of scanf is as follows:

Scanf["control string ",& variable1, &variable2…);

Where control string contains the format of data being received and also specifies

what type of data being stored into variable. & before each variable name

specifies the variable name's address.

Ex. scant("&d", &rollno);

Commonly used scanf( ) format codes are as follows :

Code Meaning

%c reads a single character

%d reads a decimal integer

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 11: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

%e reads a floating point value

%f reads a floating point value

%h reads a short integer

&I reads a decimal, hexadecimal or octal integer.

&o reads an octal integer

&u reads a string

&x reads an unsigned decimal integer

&x reads a hexadecimal integer

&[…] reads a string of words.

[b] print()

The printf() function is used to print out a message, either on screen or an paper.

The syntax of printf( ) function may be narrated as follows:

Syntax:

printf("Control string", variable1, variable2);

The control string of print( ) function/statement covers text message, escape

sequence and & codes. The print ( ) statement like all other statements in C should

be ended with a semicolon. Example:

Print(" Welcome to QUANBOOK of C");

(c) gets( )

A string is a array of characters. In simple terms, a string is a collection of more

than one characters represented together. To input string through keyboard one

can use gets function. General format of this command is …

gets (variable);

Ex. char name[15];

gets (name);

It's equivlent statement is…

scanf("%[\n]", name);

(d) puts( )

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 12: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

To display value stored in string variable, this function can be used. General

format is..

puts (variable);

Ex. puts (name);

To display a single character putchar( ) is used where as to display the array of

character, i.e. string, this function/statement is generally used. With the help of

loop construct, putchar( ) function can also display the array of characters one by

one.

(e) Write a note on getchar ( ) or getch ( ) or getche( )

The simplest of all input/output operations is reading a character from the

standard input/output device, i.e. keyboard and writing it to standard output unit,

i.e. monitor/screen. Reading a single caracter can be done by using the function

getchar( ). The syntax of getchar ( ) function is as follows:

Variable_name = getchar ( );

Variable_name is a valid C variable name that ha been declared as a character

type. When this statement is encountered, the computer waits until a key is

pressed and then assigns this character as a value to getchar function.

Char name;

Name = getchar( ),

The getchar ( ) function may be called successively to read the characters

contained in a line of text. It is important to note that getchar( ) function accepts

any character keyed in which includes RETURN and TAB even.

(f) Write a note on putchar ( ) or putch ( ) or putche ( )

Like getchar ( ) function, there is another function putchar( ) for writing

characters one at a time to the terminal.

Putchar (variable_name);

where, varible_name is a type char variable containing a character. This statement

displays the character contained in the variable-name at the terminal.

Answer= 'Y';

Putchar (answer);

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 13: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

Will display the character Y on terminal where as

Putchar (`\n');

Would cause the cursor on the screen to move to the beginning of the next line.

Q.17 Write a note on % codes used with print( ) function

OR

Explain the print format codes.

The print( ) statement is used to provide formatted output on the terminal. The

format codes plays important role ion generating formatted output. The

commonly used print format codes are listed hereinbelow.

Code Meaning

%c prints a single character

%d prints a decimal integer

%e prints a floating point value in exponent form

&f prints a floating point value without exponent

%g prints a floating point value either e-type of f-type depending on

value.

&i Print a single decimal integer

&o print an octal integer without leading zero

&s print a string

&u prints an unsigned decimal integer

&x prints a hexadecimal integer without leadiong Ox

Q-18 Explain the following decision making statements

(a) if statement

The if statement, as its name implies, is used to make decisions. If a

certain condition is true, we direct the computer to take one course of

action; if the condition is false, we direct it to do something else. This is

one of the most fundamental concept in computer science.

C allows decisions to be made by evaluating a given expression as true or

false. Such an expression involves the relational and logical operators.

Depending on the outcome of the decision, program execution proceeds in

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 14: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

one direction or another. The C construct that enables there testo be made

is called the if statement.

Syntax:

if (expression)

statement;

OR

If (expresson)

(

statement-1;

statement-2;

}

The keyword if must be followed by a set of parentheses containing the

expression to be tested. If the expression evaluates as true, the statements

in the braces will be executed, otherwise the same will be skipped by the

compiler. Consider the following segment of a program that is written for

processing of marks obtained in an entrance exam.

if total > 70

{

print(" Distinction);

}

The simple if condition can be explained with the following logical segments.

1. if (bank balance is zero)

borrow money

2. if (room is dark)

put on light

3. if (code is 1)

person is male.

4. if (age is more than 55)

person is retired.

(b) The if…else statement

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 15: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

The if statement by itself will execute a single statement or a group of statements,

where the condition is following if is true. It does nothing when it is false. To

execute one group of statements if the condition is true and another group of

statements if the condition is false, if…else statement can be used.

The general format of if…else statements can be narrated as under:

If (condition is true)

{

statement - 1;

statement -2;

}

else

{

statement-1;

statement-2;

}

A few regarding if…else is worth noting…

(1) The group of statements after the if up to and not including the else is called the if

block. Similarly the statements after the else forms the else block.

(2) The else is written exactly below the if. The statements in the if block and those in

the else block have been indented to the right.

(3) Had there been only one statement to be executed in the if block and only one

statement in the else block we could have dropped the pair of braces.

(4) As with the if statement, the default scope of else is also the statement

immediately after the else.

In case of calculating the salary of the employee or to calculate the marks of the

students, this statement can be used.

Example:

/* Calculation of Marks of Students */

/* Author : Ratish Kakkad Date : 12/12/2000 */

main( )

{

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 16: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

float m1, m2, m3, m4, m5, m6, m7, total, avg;

/* Accept marks of seven subjects*/

print("Enter Marks of Seven Subjects*/

print ("Enter Marks of Seven Subjects");

scanf ("%f %f %f %f %f %f %f", &m1, &m2, &m3,

&m4, &m5, &m6, &m7);

/* Calculate the total of marks obtained in 7 sub*/

total = m1+m2+m3+m4+m5+m6+m7;

avg = total /7;

if (avg>35)

{

print("Pass");

}

else

{

print ("fail");

}

(c) Nested … if condition

It is possible to write an entire if…else construct within the body of the if

statement or the body of an else statement. This is called the nesting of ifs.

The second if… else construction is nested in the first else statement. If the

condition in the first if statement is false, then the condition in the second iof

statement is checked. If it is false as well, the final else statement is executed.

The general format of Nested… if is as follows :

If (condition)

{

do this;

}

else

{

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 17: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

if (condition)

do this;

else

{

do this;

and this;

}

}

(d) Switch statement

The switch statement permits virtually any number of branches. The direction of

the branch taken by the switch statement is based on the value of any variable or

expression. The variable or expression is placed in the parentheses following the

keyword switch.

The body of a switch statement is enclosed in braces. The form of the statement is

unique. It consists of case labels, which take the form of the keyword case

followed by a constant value. This value should be of the same type as the switch

variable; it must be an int or int-compatible value. A colon follows the case label.

The switch works as follows: When the statement is encountered, the switch

variable or expression is evaluated to yield a specific value. Program control is

transferred to the statement immediately following the case label whose constant

is equal to the value of the switch variable or expression. This statement is

executed, followed by all the succeeding statements in the body of the switch

statement.

A special label, default can be placed. This label is to allow for the possibility that

the value of the switch expression does not match ay of the case labels.

The switch statement most often appears as follows :

Switch (integer expression)

{

case constant 1:

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 18: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

do this;

case constant 2:

do this;

case constant 3:

do this;

default:

do this;

]

[e] The goto statement

C support the goto statement to branch unconditionally form one point to another

in the program.

The goto required a label in order to identify the place where the branch is to be

made. A label is any valid variable name, and must be followed by a colon. The

label is placed immediately before the statement where the control is to be

transferred.

Goto label; label:

____________ _________

____________ _________

____________ _________

label; goto label;

It is important to note that goto breaks the normal sequential execution of the

program. If the label is placed before the statement goto label, a loop will be

formed and some statements will be executed repeatedly. Such a jump may be

identified as a backward jump. On the other hand, if the label is placed after the

goto label statement, some statements will be skipped and the jump is known as a

forward jump.

main ( )

{

int I;

I = 1;

ABC:

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 19: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

print ("%d", I);

I = I+1:

if (I<100)

Goto abc;

}

The above referred program is written to create a series from 1 to 100. The control

will passed as a backward jump and a loop will work to print the numbers from 2

to 99.

Q-19. Explain following loop contructs

(a) while loop

(b) do-while loop

(a) while loop

A Segment of the code that is executed repeatedly is called a loop. The loop

concept is a part of good programming. Each of the loop contains three

expressions, i.e. initialisation, condition and counter expressions. The general

form of the while loop is :

While (condition)

{

statement 1;

Statement 2;

}

So long as the condition is true, the statements, i.e. the body of the loop is

executed. Note tat the condition tested before the statements are executed. If there

is only one statement in the body of the while loop then the pair of braces may be

dropped.

As the while is a entry-controlled loop statement, the test-condition is evaluated

and if the condition is true, then the body of the loop executed.

Example:

Main ( )

{

int I;

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 20: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

I = 1; initialization

While (I<100) condition

{

print("%d", I);

I = I+1; increment/counter

}

}

Each loop has three segments, i.le. initialisation, condition and counter/increment.

(b) Do-while Loop

The do… while loop (sometimes referred to as do loop) differs from its

counterpart while loop. Even if the condition is false, when the do… while loop is

first encountered, the body of the loop is executed atleast once. If the condition is

false, after the first loop iteration, the loop terminates. If the first iteration has

made the condition true, however, the loop continues.

The do… while loop looks like this:

do

{

this;

and this;

and this;

} while ( this condition is true);

The following figure would clarify the execution of the do… while loop further:

-------

Q.20. Write a note on For Loop

OR

Explain the role of initialization, condition and counter (increment) in a for

loop. When are each of them executed?

In most of the loops, first the variable is used in the loop conditions is initialised.

Next execution of the loop begins. A test, i.e. condition is made at the beginning

of each iteration. The body of the loop ends with a statement that modifies the

value of the test variable or variables i.e. increment counter.

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 21: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

Because this looping method is so common, C provides a sort of abbreviated

version of this conduct, call the for loop. Its general form is as follows:

For (expression-1, expression-2; expression-3)

{

body of the loop

}

Expression-1 is the initialisation expression, usually as assignment, which is

performed once before the loop actually begins execution. Expression-2 is the

test, i.e. condition and the expression 3 is the increment/decrement counter.

Example :

{

int I;

for(I=1, I<100;I++)

{

print ("%d", I);

}

}

)

Q-21. Narrate the use of break statement in loops.

OR

Explain the significance of the break statement in the switch case construct.

What would result in its absence?

When the statement

Break;

Is encountered during execution, the control immediately comes out of the

corresponding while, do…While, for or switch and reaches the statement

immediately after the while, do…While, for or switch.

Q-22 Narrate the use of continue statement in loops.

When the statement

continue;

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 22: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

is encountered in a while, do… While, or a for loop control passes to the

condition that determines whether to execute the body of the loop again or not.

Continue cannot be used with switch, the way break can be.

For example

For (I=12; I<45; I++)

K = | * 7 +b;

If (k<1000)

Continue;

Else

Print("%d",k);

Here on encountering continue control passes to I++, which increments the value

of I and then passes control to I<=45, which determines whether the body of the

loop should be executed or not.

Q.23 Write a note on ARRAY in C.

An array is a group of elements that share a common name, and that are

differentiated from one another by their position within the array.

An array must be declared, since it is a type of variable. An array containing five

elements, all of which are integers, can be declared as follows:

Int × [5];

An array name must be choosen according to the same rules used for naming any

other variable. The name of the array cannot be the same as that of any other

variable declared within the funtion. The size of the array is specified using the

subscript notation; in our example, the subscript 5 indicates how many elements

are to be allocated to array x.

The subscript used to declare an array sometimes is called the dimension and the

declaration itself often called dimensioning. As the regular variables, declaration

does not assign values, but simply set aside memory for the array. The dimension

used to declare on array must always be a positive integer constant or an

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 23: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

expression that can be evaluated to a constant when the program is compiled. The

characteristics of an array can be smmarized as follows:

1. An array is a collection of similar elements stored in adjacent memory locations.

2. Before using an array its size and type must be declared.

3. The first element (subscript) in the array is numbered O, so the last element is 1

less than the size of the array.

4. If array elements are not given any specific values, they are supposed to contain

garbage values.

5. There is no check to see if the subscript used for an array exceeds the size of the

array. Data entered with a subscript exceeding the array size will simply be placed

in memory outside the array; this will lead to unpredictable results.

Q.24 What is user defined function ? Explain the need of user defined functions.

OR

What is user defined function? Narrate the advantages of modular

programming?

C functions can be classified mainly into two categories, namely user-defined

functions and library functions. Main ( ) is a user defined function while print ( )

and scanf ( ) are library functions. The main distinction between these two

categories is that library functions are not required to be written by us whereas a

user-defined function has to be developed by the user at the time of writing a

program. However, a user-defined function can later be a part of the C program

library.

When, a program is coded utilizing only one main function, it leads to a number

of problem. The program may become too large and complex as a result the task

of debugging, testing and maintaining becomes too large and complex and as a

result the task of debugging, testing and maintaining becomes difficult. If a

program is divided into functional parts, then each part may be independently

coded and later combined into a single unit. These subprograms called 'functions'

are much easier to understand, debug and test. It may be summarized that a

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 24: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

function is a self-sections approach results in a number of advantages listed

hereinbelow:

(1) It facilitates top-down modular approach programming. In this programming

stype, the high level logic of the overall program is solved first while the details

of each lower-level function are addressed later.

(2) The length of a source program can be reduced by using functions at appropriate

places. This factor is particularly critical with microcomputers where memory

space is limited.

(3) As mentioned earlier, it is easy to locate the isolate a faulty function for further

investigation.

(4) A function may be used by other programs.

Q.25 Discuss the form of a C function.

All functions which may be used in a C program should have the following form

or format;

Function-name (argument list)

Argument declaration;

{

local variable declaration;

executable statement1;

executable statement2;

return (expression);

}

A function must follow the same rules of formation as other variables names in C

as regards the function name. The argument list contains valid variable names

separated by commas. The list must be surrounded by parentheses. No semicolon

follows the closing parenthesis. All argument variables must be declared for their

type after function header and before the opening braces of function body.

A function may or may not send back any value to the calling function. If it does,

it is done through the return statement.

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 25: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

Q.26 What is recursion ?

In C, it is possible for the functions to call themselves. A function is called as a

recursive if a statement within the bldy of the function calls the same function.

Sometimes called as Circular definition, recursion is thus the process of defining

something in terms of itself.

Example:

Main ( )

(

int a, f;

print(" Enter any number");

scanf ("%d", &a);

f=recfact(a);

printf ("\n Factorial value = %d", f);

}

recfact(x)

int x;

{

int fact;

if (x==1)

return(1);

fact = recfact (x-1)"x;

return (fact)

}

When writing recursive functions, you must have an if statement somewhere in

the recursive function to force the function to return without recursive call being

executed. If you don’t' do this and you call the function, you will fall in an

indefinite loop and will never return from the called function which is a very

common error in writing recursive functions.

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 26: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

It is suggested to use print( ) statement during the development of the recursive

function to enable the user to watch what is going on and can abort execution if

you see that you have made a mistake.

Q.27. What is a structure? How to declare it ?

Structures constitute a sort of super data type, which can represent several

different types of data in a single unit. A structure definition is specified by the

keyword struct. A template surrounded by braces describes the members of

structure. Note that members of a structure are not variables. Only when a

structure variable is declared do the members come to represent locations in

memory.

C supports a constructed data type known as structure, which is a method for

packing data of different types. A structure is a convenient tool for handling a

group of logically related data items. A structure definition creates a format

that may be used to declare structure variables. The general format of

structure definition is as follows :

Struct tag-name

{

data type member-1;

data type member-2

Consider a book database consisting of book name, author, number of pages, and

price. We can define structure to hold this information as follows:

Struct bookbank

{

char title [20];

char author [15];

int pages;

float price;

}

We can declare structure variables using the tag name anywhere in the program.

For example:

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 27: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

struct bookbank book 1, book2, book3;

describes book1, book2 and boo3 as the variables of type struct bookbank.

Q.28 Write a note on Concept of Arrays of Structures

In array of structure, the structure variable is assigned to a array. Suppose, we

want to get the result of 10 students and the marks of 3 subjects per student, the

structure will contain the records of 3 subject and the structure variable will be an

array having 10 subscript values.

Struct marks

{

int subject-1;

int subject-2;

int subject-3;

};

will store the marks of 3 subjects. To store the result of 10 students we should

assign struct marks class[10]; will give 10 subscript values to class which contains

3 records per subscript.

Q-29 What is a Pointer? Explain.

When an identifier identifies a memory location, which holds some value, is

called variable, if it identifies memory location that holds address of memory cell

is called pointer.

Pointers are much used in C, because:

1. A pointer enables us to access a variable that is defined outside the function.

2. Pointers are more efficient in handling the data tables.

3. Pointers reduce the length and complexity of a program.

4. They increase speed if execution.

5. The use of a pointer array to character string results in saving of data storage

space in memory.

To declare a variable as pointer, one has to use Value At Address Operator (*).

It returns the value stored at a particular address. It is also called direction

operator. Another operator used with pointer is & (Address of operator).

Ex. int |=5, *I;

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 28: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

I=&l;

printf (" value %d stored at %u address ", *I, I);

These statements tell the C compiler

1. Reserve the space in memory.

2. Associate name 1 with memory location.

3. Store value 5 at this location.

4. Assign address of | to pointer variable i.

You can access value 5 using variable | or by pointer variable i. Instead of array

pointer provides much faster access to your operation. You can use pointer with

any type of data type like int, cha float as well as with structure and function too.

We will discuss here how to use pointer with all these data types.

Q.30 Write a note on Array of Pointers

When an array is declared, value stored in contiguous memory locations. The base

address is the location of the first element of the array. If array contains 5 element

and the base address is 1000 the other element stored at address 1002, 1004, 1006,

1008. So if we declare p as an integer pointer as follows:

Int *p,x[5];

P =x; // equivalent to p=&×[0];

We can access every value of × using p++ to move from one element to another.

Example:

#include <stdio.h>

#include <conio.h>

main( )

{

int no[5], I, *I;

for (I=0;<5;I++)

scanf(%d", & no(i);

j=no;

for (I=0;I<5;I++)

<

printf(" %d", *I);

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 29: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

I++; // give two statements or print("%d", *(I+I));

}

}

Q.31 What is character pointer? Explain the use of pointers in defining character

string.

As we know string is an array of characters; terminated with a null character. You

can use character pointer to access each character of string. Rather than use

pointer in declaration of string, so that size can be ignored at the time of

declaration.

Example:

#include<conio.h>

main ( )

{

char *s; // length of string is not required in case of pointer

clrscr( );

print ("enter string : “);

gets (s);

puts ("\n string is … ”);

puts(s);

}

Q-32. Write a note on use of Pointers in Structures.

The pointers can be used in structures to make the execution fast and efficient. As

we know structure is a combination of more than one field of different data types,

the use of pointers in structure make it more easier to address the subscript of any

element of the structure. You can use pointer to access each element of the

structure. In a function call, if we refer pointe makes it more easier for the

programmer to pass the structure as a argument, i.e. actual argument.

Example:

#include<stdio.h>

#include<conio.h>

struct stud

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 30: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

{

char *name;

int age;

};

main ( )

{

struct stud st[3], t;

int I;

clrscr( );

for (I=0; I<3;I++)

{

fflush(stdin);

print(" &d student NAME :",I+1);

gets(st[I].name);

printf(“%d“&st[I]. age);

}

t=&st;

clrscr( );

print{“nName Age");

print(“\n-----

for (I=0;I<3;I++, t++)

printf(“n%-15s %3d",t->name, t->age);

getch( );

}

Q-33 How union differs from a structure?

The way of declaring structures and unions are same. In general use, the

beginners refer structures and unions as the same but in actual, the structures and

unions differs from each other in the following sections, i.e. parameters.

[a] Memory Allocation

[b] Operation members

[c] Identifying Active Members.

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 31: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

Q-34 What is file function? Explain the usage of file functions in C.

Following functions are useful for file handling through c program. We can read

and write data in a file same as we print data on screen and read inputted data

through keyboard. But there are several important differences between file 1/O

and console 1/0. They are…

The console always exists, but file may or may not exist.

In console generally data will be inputted through keyboard and display on

screen. While in file it is possible to read from and write to the same file.

General sequence for file 1/O is always as:

Open file in specified mode.

Access the file with read or write operation.

Close the file.

Q-35. Explain the function; fopen ( )

Before accessing any file, file must be opened. While opening the file the

following cammand can be used.

Syntax:

File pointer = fopen (“file name”, “mode");

Ex.

FILE *fp;

Fp = fopen(“trial.txt”, ”r”);

FILE is a reserve word used to define file pointer to a FILE structure. In the next

statement function returns pointer to the file structure which it created. Different

available modes are…

MODE MEANING

r Open for reading only.

W Create for writing and if the file already exist, it will be overwritten.

A Append, open for writing at the end of file (create for writing it it does not

exist.)

R + Open an existing file for update (reading & writing)

W+ Create a new file for update. If the file already exist, it will be

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 32: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

overwritten

A+ Open for append, open for update at the end of the file.

Q-36 Explain the function; fclose( )

Closing the file flushes the buffer and releases the space taken by the file

structure. Which is returned by fopen. (During a write to a file, the data written is

not put on the disk immediately. It is stored in a buffer when the buffer is full, all

its contents are actually written to the disk. The process of emptying the buffer by

writing its contents to disk is called flushing the buffer.)

Function used to close file is…

Syntax; fclose(file pointer);

Ex. fclose(fp);

Q-37 Write a note on following file functions

[1] fprint( )

[2] fscanf( )

[3] fgetc( )

[4] fputc( )

[5] fwrite ( ) and fread ( )

[1] fprint( )

Same as printf, but instead of console it writes to associated file with file stream.

Syntax:

Fprint(file pointer, const char (format, arguments…);

Where, const char *format contains conversion specifications.

Ex. fprint(fp,”%s %d”, name.rollno);

[2] fscanf( )

It deals with formatted ionput conversion.

Syntax : fscanf(file pointer, const char *format, arguments…);

Ex. :fscanf(fp,”%s “%d”, name,&rollno);

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 33: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

[3] fgetc( )

It is same as getc function. It returns the next character from a named input

stream. If error or end of file encountered it returns EOF.

Syntax : fgetc(file pointer);

Ex. : ch=fgetc(fp);

Statement returns next character of a file to variable of type character.

[4] fputc( )

This function stores character to a specified stream.

Syntax : fputc(int, file pointer);

Ex. : fputc(ch, fp);

As fputc and fgetc functions are used for character handling, fgets and fputs are

used for string handling in file 1/0.

[5] fwrite ( ) & fread ( )

When you want to perform are used for character handling, fgets and fputs are

used for string handling in file 1/O.

[5] fwrite( ) & fread ( )

When you want to perform 1/O operation using structure fread and fwrite are

most useful one.

Function fwrite appends specified no. of equal sized data to a output file while

fread returns a specified no. of equal sized data from an input stream into a block.

Syntax : fread(void *ptr,size,n,file *stream);

Fwrite(void *ptr, size,n, file *stream);

Where, First argument ( *ptr) is the address of the structure to be written to the

disk. The second argument(size) is size of the structure in bytes. The third

argument(n) is the no. of items that we want to read or write, Last argument(file

pointer) is the pointer to the file to which we want to read or writer the structure.

Example :

Fread(&emp.sizeof(emp), 1, fp);

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 34: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

Fwrite(&emp, sizeof(emp), 1, fp);

Q-38 Mention two differences between a text file and a binary file

Microsoft Disk, Operating System treats files in two different ways, i.e. as binary

files or text files. If a file is specified as the binary type, the file 1/O functions do

not interpret the contents to the file when they read from, or write to the file. But

if the file is specified as the text type, the file 1/0 functions interpret the contents

of the file. The basic differences in these two types of files are:

[a] ASCII O×1a is considered as end-of-file character by the file 1/0 functions when

reading from a text file and they assume that the end of file has been reached.

[b] In case of DOS, a new line is stored a the sequence O×Od O×Oa both on disk and

in memory.

Q-39 Why a linked list is called a dynamic data s structure? What are the

advantages of using linked lists over arrays?

A linked list is a dynamic data structure. therefore, the primary advantage of

linked lists over array is that linked lists can grow or shrink in size during the

execution of a program. A linked list can be made just as long as reguired.

Another advantage is that a linked list does not waste memory space. It uses the

memory that is just needed for the list at any point of time. This is because it is

not necessary to specify the number of nodes to be used in the list.

The third, and more important advantage is that the linked lists provide flexibility

in allowing the items to be rearranged efficiently. It is easier to insert or delete

items by rearranging the links.

The major limitation of linked lists is that the access to any arbitrary item is little

cumbersome and time consuming. Whenever we deal with a fixed length list, it

would be better to use an array rather than a linked list. We must also note that a

linked list will use more storage than an array with same number of items because

each item has an additional link field.

Q-40 Describe different types of linked lists.

There are different types of linked lists. They can be listed as below:

[1] Singly Linked lists.

[2] Circular Linked lists.

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 35: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

[3] Two way or doubly linked lists.

[4] Circular doubly linked lists.

The circular linked lists have no beginning and no end. The last item point back to

the first item. The doubly linked lists uses double set of pointers, one pointing to

the next item and other pointing to the preceding item. This allows us to traverse

the list in either direction. Circular doubly linked lists employs both the forward

pointer and backward pointer in circular form.

Q-41 Explain the role of C preprocessors.

The preprocessor as its name implies, is a program that processes the source code

before it passes through the compiler. It operates under the control of what is

known as preprocessor command lines or directive. Preprocessor directives are

placed in the source program before main ( ) line. Before the source code passes

through the compiler, the preprocessor for any preprocessor directives examines

it. if there are any appropriate actions are taken and then the source program is

handed over to the compiler.

Preprocessor directives follow special syntax rules that are different from the

normal C syntax. They all begin with the symbol # in the column one and do not

require a semicolon at the end. The preprocessor directives can be divided into

three categories:

[1] Macro Substitution Directives.

[2] File inclusion Directives.

[3] Campiler Control Directives.

The following is a list of preprocessor directives

Directive Function

#define Defines a macro substitution

#undef Underfiones a macro.

#include Specifies the files to be included

#ifdef Tests for a macro definition

#endif Specifies the end of #if

#ifndef Tests whether a macro is not defined.

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 36: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

#if Tests a compile time condition

#else Specifies alternative when #if test fails.

Q-42 What is a macro and how is it different from a C variable name?

Macro substitution is a process where an identifier in a program is replaced by a

predefined string composed of one or moretakens. The preprocessor accomplishes

this task under the direction of #define statement. This statement, usually known

as a macro definition takes the following format.

#define identifier string.

Simple string replacement is commonly used to define constants. The following

are the examples of constants:

#define identifier string.

Simply string replacement is commonly used to define constants. The following

are the examples of constants:

#define COUNT100

#define FALSE 0

A macro definition can include more than a simple constant value. It can include

expressions as well.

Q-43. What precautions one should take when using macros with arguments?

The pre processor permits us to define more complex and more useful form of

replacements. There is a basic difference between simple replacement and the

replacement of macros with arguments. Subsequent occurrence of a macro with

arguments is known as macro call. when a macro is called, the preprocessor

substitutes as string, replacing formal parameters with the actual parameters. Here

the string behaves like a template.

Q-44 When does a Programmer use #include directive?

An external file containing functions or macro definitions can be included as a

part of a program so that we need not rewrite those functions or macro definitions.

This is achieved by a preprocessor directive

#include "filename"

where a filename is a name of the file containing the required definitions or the

functions. When the filename is included with double quoted marks, the search

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 37: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

for the file is made first in the current directory and then in the standard

directories.

Alternatively this directive can take the form:

#include <filename>

We can make use of a definition or a function containing needed instruction by

including them in the program as shown hereinbelow:

#include <stdio.h>

#include "SYNTAX.C"

Q-45. What is the difference between a macro and a function ?

Macro call and function call although call something which may be defined as a

variable. In a macro call, i.e. pre-processor directive replaces the macro template

with its macro expansion while in a function along with their arguments and

retunes back with useful value.

With the help of macro, program runs faster but on the other hand, increases the

program size which is against structured programming whereas functions make

the program smaller and compact but makes the processing/exection slower.

It is to be suggested/advocated that if there is a small function, it is advisable to

use macro and in big branches, functions are useful.

Q-46 What is COMMAND LINE ARGUMENTS? What its' significant in a c

program.

As we all know C language was developed under the UNIX operating system. Ion

Unix when you execute any compiled program, the program name (like a

command at prompt) can be followed by various arguments on the same line.

Which specifies how the program is to operate. C compiler also provides facility

where by the program can access command line arguments. In short it is a

parameter supplied to a program when the program is invoked. Main function

may have two arguments they are…

A. argc (Argument counter)

B. argv (Argument vector)

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 38: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

argc is always type of integer. It contains total no. of argument passed to main

function. Whereas, argv is a pointer to an arrayof character string that contain the

arguments one per string.

In order to be able to access command line arguments, the main function of the

program must be defined as having two arguments as given below:

main (int argc,char *argv[])

Example :

Following program shows the use of command line argument to find the

multiplication of numbers passed as arguments to main function.

// program name : GUNAKAR.C

#include <stdio.h>

#include <conio.h>

main(int argc,char *argv[])

{

long int m=1, k;

clrscr( );

if (argc<2)

{

printf(“two few arguments…”);

getch ( );

exit(0);

}

for (k=1;k<argc;k++)

m=m *atoll (argv[k]);

pritnf(“Answer = %ld", m);

getch( );

}

While executing at prompt you may give commands as:

Gunakar 1 2 3 4 5

Output: Answer = 120

Here,

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 39: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

Argc will be 4.

Argv[0]= program name i.e. gunakar

argv[1]=”1"

argv[2]=”2"

argv[3]=”3"

argv[4]=”4"

argv[5]=”5"

Q-47 What is DYNAMIC MEMORY ALLOCATION ?

It is important to programmers to write programs that use a minimum of memory

as well as programs that are fast. But most often we face situations in

programming where the data is dynamic, means number of data items keep

changing during execution of the program. Array can be used fro mass data but

they are of fixed size. The programmer must know the size of the data or array

while writing the programs. But it is not possible to know the exact size of

memory required until run time; here dynamic memory allocation is required.

C. provides facility to allocate memory for the local variables from heep (the

program instruction and global variables are stored in a region known as

permanent storage area and the local variables are stored in another area called

stack. The memory space the located between these two regions is available for

dynamic memory allocation during execution of the program. This free memory

region is called the heap) while executing a program is known as Dynamic

Memory Allocation. It means size of memory required is not pre determined but

as per users requirement it will be allocated after execution being started. You

may use calloc( ), malloc ( ) free ( ) and realloc ( ) functions by dynamic memory

allocation.

Q.48 Write a note on Functions which may be used for Dynamic Memory

Allocation

The header file associated with these functions is <stdlib.h>.

char * calloc(int items, int size);

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 40: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

This function is usd to allocate dynamically a block of memory for nitems

elements of size bytes each. That is, the total number of bytes allocated us nitems

* size. The block of memory is cleared to zeros. A pointer to the allocated block is

returned. It can be cast into a pointer of any type.

void free(char *block);

This function de-allocates the block of memory pointed to by block, making it

available for latter allocation. The block must have been allocated by a previous

call to caloc, malloc or realloc, but not preciously freed by a call to free. Once a

block of memory is freed, it should not be referenced.

Char *malloc(int size);

This function is used to allocate dynamically a block of memory of size bytes.

The block of memory is not initialised. A pointer to the allocated block is

returned.

char realloc(char *old, int size);

This function extends or reduces the dynamically allocated block pointed to by

old to the size specified by size. The block must have been allocated by a previous

call to caloc, malloc or realloc, but not previously freed by a call to free. The new

block can begin at a different memory location that the old block. The new block

has the same value as the old.

Difference between Calloc( ) and malloc ( )

Calloc function allocates memory in block of specified size and another

difference is calloc function initialises all bytes in the allocated block to zero.

Q-49 What is Union? What its significance? How it is different from structure?

Union is also derived data type like structure. A union is declared exactly like a

structure, except that the keyword union is used instead of struct and union can

never be initialised.

Union provide a way to manipulate different kinds of data in a single area of

storage, means in union two data items still are separate in terms of syntax, but

they share the same portion of memory. In other words we can say a union can

contain as many numbers as desired, of any type, but it allocates only enough

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 41: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

memory to hold the largest member. Union may occur within structure, arrays and

visa versa. Member of union are accessed as …

Union name.member

Example :

Union group

{

int nmem;

float income;

} gp;

This declares a variable g[ of type union group. The member of gp are referred to

as gp.nmem and gp.income. gp contains memory for one value, either an int or a

float, as specified in the body of the union. Integer required 2 bytes, while float

required 4 butes, the variable gp contains 4 butes in memory. It can be referred to

as either a float variable or an int variable.

If a value is assigned to gp.nmem, then value stored in gp in integer format in the

memory locations belonging to gp. If value is passed to gp.income, then value

stored in gp in float format in the memory locations belonging to gp.

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 42: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

SHORT QUESTIONS

[1] What is a variable ?

It is a symbolic name for a memory location in which a value is stored.

[2] What is an Integer ?

It is a whole number, one without a decimal point.

[3] Why the assignment statement regarded as symbolic?

Because during execution of the program, the expression to the rights of the equal

sign is reduced to a single number which is then stored in variable specified on

the left.

[4] How many variables may appear on the left of the eqal sign ion an

assignment statement?

Only one

[5] What are the rules for the naming of variables ?

They must begin with a letter [including the underscore], may contain only letters

and digits, may not include special characters may not be a keyword and the first

eight characters or so [depending upon the implementation] must be unique.

[6] What purpose is served by including white space in a program?

It highlights program statements and output, and makes the program listing easier

to read.

[7] Which of the two operators, multiplication or division has the higher

precedence?

Neither; they have the same priority level. If they are both present, they are

evaluated from left to right.

[8] Distinguish between the binary and the unary minus.

The binary minus has an operand before and after the minus sign, and is used for

subtraction. The unary minus has only one operand - to its right - and serves to

convert a positive value into its corresponding negative value and vice versa.

[9] What is meant by truncation?

It is the rounding down effect achieved, among other times, when an integer is

divided by another integer and resulting fractional portion is chopped off.

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 43: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

[10] What role is played by parenthesis in evaluating expression?

They override the normal priorities. What is contained within the parenthesis is

evaluated first, in the normal order.

[11] What is the modulus operator and how does it work ?

It is represented by the symbol %. It finds the remainder that is left when one

integer is divided by another integer.

[12] What is another name for floating point numbers?

Real numbers.

[13] What is the keyword that is used to declare floating point variables?

Float or double.

[14] What distinguishes floating point numbers from integrs?

Floating point numbers have a broader range; may have a fractional portion; are

stored differently; use the %e of %f conversion specifier rather than %d; and may

result in slower operations.

[15] What is a character constant?

It is a single character enclosed by single quotation marks.

[16] What is the maximum number of characters, which a variable of type char

can hold?

One

[17] What function enables a user to ionput information while the program is in

execution ?

The Scanf( ) function

[18] Which statement in C permits decisions to be made?

The if statement

[19] How many relational operators are there and what they are?

Six, as follows:

== equal to

!= not equal to

>= grater than or equal to

<= less than or equal to

< less than

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 44: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

> greater than

(20) What is the function of the else clause in an if statement?

If present, it is followed by a statement that is executed only if the condition being

tested proves to be false.

(21) What is a nested if statement?

An if statement in which the if clause or the else clause contains another if

statement.

[22] What is the difference between two operators = and = =?

The single equal sign means assignment whereas the double equal sign is a

relational operator used for testing purpose.

[23] Which operators can be used with the updating assignment operators?

All binary operators (+,-,*,/,% and others) can be used with the updating

assignment operators.

[24] What is the difference between pre-decrement and post-decrement

operators?

The pre-decrement decreases the value before the test expression while the post

decrement operator will decrease the value after the completion of the test

expression.

[25] What is the essential difference between a while and do..while loop?

A while loop prefers its test before the body of the loop is executed, whereas a

do… while loop makes the test after the body is executed.

[26] What happens if a condition in a while loop is initially false?

The whole loop is skipped over.

[27] Which is the better loop to use, the for loop or the while loop?

It depends on the nature of the problem to be solved, and upon the preference of

the programmer.

[28] Which is a special advantage of the for loop ?

The initialisation, condition and counter, i.e. modifier expression of the loop all

are specified within a single set of parenthesis.

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 45: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

[29] How does the for loop operates?

The first expression is executed once. Then the second expression is tested and if

it evaluates as true, the body of the for loop is executed. Then the third expression

is executed. [Usually to change the value of condition expression, i.e. test

variable] Once again the second expression is evaluated. As long as the second

expression is true, the body of the loop is executed, followed by the third

expression. When the second expression evaluates as false, the loop terminates.

[30] What is C pre-processor?

It is the first step in the compilation of a C program, which performs several

initial tasks, including the processing of constant definitions.

[31] What is meant by a nested for loop ?

In nested for loop, the body of one for loop contains another for loop.

[32] When is the comma operator used in a for loop ?

When the first [initialisation] and/or third [counter/modifier] expression of the for

statement contain more than one expression.

[33] What conversion specifications are used to print out the following ?

[a] an Integer

[b] a floating point number in decimal point.

[c] a floating point number in scientific notations.

[d] a single character.

%d is used for Integer, %f for floating point number in decimal point, %e

fro exponent values and %c for single character.

[34] What does the word ASCII stands for?

American Standard Code for information Interchange, which is the most popular

code used fro microcomputers.

[35] Which letters have higher ASCII values, upper case of lower case?

Lowercase characters.

[36] What are the ASCII codes for A to Z ?

65 to 90 respectively.

[37] What are the control characters?

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 46: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

The control characters are the unprintable characters through which the user can

control the output.

[38] Give some examples of control characters.

Backspace, tab, newline, carriage return, from feed and bell can be narrated as the

examples of control characters.

[39] How can a % sign be printed within a control string ?

By using two adajacent % signs.

[40] What is the difference between conversion specification letters used in printf

and those used ion scanf?

Generally there is no difference in the set of letters used. There is some difference

in operation, however; for example, %f is used in print always displays a floating

point number in decimal notation, but when it is used in scanf, it is equivalent to

%e, both of which accept a number ion either decimal or scientific notation.

[41] Distinguish between a user defined function and one supplied in the C

library?

The statements of a user-defined function are written as part of the program itself,

according to the programmer@ requirements whereas the library functions

available with C compiler is a readymade set of instruction which can be used by

the user in its as it is format.

[42] When is the execution of a function terminated?

Either when it executes the return statement or when the last statement in the body

of the function is executed.

[43] How many values can a function return ?

One

[44] What is the major difference between a function and a procedure?

A procedure does not return a value, while a function does. In C, the term

procedure is not used, since functions that return values are identical in overall

structure to those that do not.

[45] What is the meaning of the term debugging?

The work of finding and eliminating of errors from program is known as removal

of bugs [errors], i.e. debugging.

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 47: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

[46] What are the rules regarding the naming of a function ?

They are the same as for naming of variables.

[47] How often a function can be called?

As many times as needed.

[48] What does modular programming mean?

A program should be broken down into smaller sub-tasks, which ion turn may be

broken down again, so that the lowest -level functions are as simple as possible

(within reason).

[49] How is a function invoked?

Its name is specified, followed by a pair of parentheses, which contain the

parentheses if needed.

[50] What role does the return statement play?

It specifies the value to be returned by the function. It also terminates the

execution of the function.

[51] Where are global variables placed within a program?

Outside all function definitions, usually at the beginning of the program.

[52] Distinguish between local and global variables.

Local variables are declared within the body of the function. They can be referred

to only within the function, and they disappear once the function finishes

execution. Global variable are declared outside the function definitions, can be

referred to from any function, and remain in existence for the entire execution of

the program.

[53] What is a formal or dummy parameter?

It is like a local variable but is used to hold a value passed from the calling

function when a function is called.

[54] What values are returned by a Boolean function ?

Zero, representing false, or a non-zero value, representing true.

[55] How many parameters can be passed to a function ?

As many parameters as are specified in the function definition.

[56] What is an array?

An array is an ordered collection of elements that share the same name.

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 48: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

[57] What are the rules for naming arrays?

The rules for naming arrays are as for naming regular variables or function. An

array cannot have the same name for a variable or function within same program.

[58] What is the purpose of initialising an array?

Before any element of an array can be used, it must have a value. Initialising an

array gives a value to each of its elements.

[59] What is the use of break statement?

It provides a means of immediately terminating the execution of a loop.

[60] What criticisms can be levelled against the break statement?

It violates the tenets of structured programming, In that it permits a jump to

another part of the program.

[61] How is a string stored in an array in C?

It is terminated by the null character, which has the ASCII value 0 and is written

in C a “/0“

[62] What conversion specification usually is used to read in a string?

%s

[63] Is it obligatory to use all the elements of an array?

No, but the program must keep track of how many elements are being used, and

which ones.

[64] When a one-dimensional array is being declared, under what condition may

the dimension be omitted, with the array name followed by an empty pair of

square brackets?

If the entire array is being initialised within the declaration.

[65] What happens if the number of initialising values is greater than the

dimension specified for the array?

A syntax error occurs during compilation of the program, and the compilation is

aborted.

[66] What is the maximum number of dimensions an array in C may have?

Theoretically, there is no limit. The only practical limits are memory size and the

restrictions imposed by the compiler being used.

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 49: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

[67] What numeric value is associated with every memory location ?

Its address.

[68] How are variables names translated to their corresponding addresses?

With the &(address) operator.

[69] Why is it desirable in C to be able to refer to a particular memory location by

its address?

That is the only way a function can refer another function@ local variables.

[70] Why is it necessary to distinguish between a variable address and the

contents of that location ?

The content of variable may change during execution of the program, but its

address cannot be changed.

[71] What is the role-played by the & operator in a call to the scanf function ?

It passes the address of the variable being input, making it possible for the

contents of that location to be changed.

[72] What are the restrictions regarding the use of the & operator?

It can be used only before the name of a scalar variable or a subscripted array

element, not before an unsubscripted array name or an expression.

[73] Can addresses be stored? If so, where?

Addresses can be stored in pointer variable.

[74] What is the indirection operator, and what role does it play?

The indirection operator is the asterisk (*). When placed before the name of a

pointer variable, it means that the location being referred to is not pointer variable

but the location pointed out by the pointer variable.

[75] What does passing of reference mean?

Passing by reference is the term used to refer to the passing of a variable address

to a function.

[76] What is the fundamental difference between passing by value and passing by

reference?

When a variable is passed by value to a function, only its value is passed. The

function cannot change the contents of the variable. Passing by reference means

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 50: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

that the variable address is passed, giving the function the power to change the

contents of that variable.

[77] When a function is written to swap the value of two variables, what special

provisions must be made?

The parameters must be the addresses of the variables, and the contents of the

locations pointed to by the addresses must be exchanged.

[78] In what ways are arrays and pointer involved with each other?

The un-subscripted name of an array is interpreted as constant pointer; only a

pointer to an array can be passed to a function; any pointer variable can be

subscripted.

[79] Why & operator is not used with the array names in a scanf statement?

Since the name of an array is already & constant pointer, the & would be both

illegal and redundant.

[80] Why is only the address of an array's first element necessary in order to

access the entire array?

Since all the elements of an array are of the same type, and all the elements are

stored contiguously in memory, the location of the first element can be used to

find the second element, the third element and so on.

[81] In what order must the parameters of a function be declared?

They may be declared in any order.

[82] What can be said about adding an integer to a pointer?

It is illegal. It returns to a pointer, which is the original pointer incremented by the

number of target units specified by the integer.

[83] Under what circumstances can be pointer be subtracted from an integer?

Under no circumstances, it is legal. [The pointer can be caste into an integer, but

this rarely would have any value]. It is however, legal to subtract an integer from

a pointer.

[84] What is returned when a pointer is subtracted from a pointer and under

what conditions is tat permitted?

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 51: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

The result is the distance between pointer expressed in target units. The two

pointers must be of the same type, and the first pointer must have a greater value

than the one being subtracted from it.

[85] What are the conditions under which the <and> operators are meaningful

when used with pointer?

The two pointers must point to elements of the same array.

[86] Why it is harder to compare string than numeric values?

String cannot be compared in a single operation; each character must be compared

with its corresponding element in the other array.

[87] How can an array of strings be represented in C?

As a two-dimensional array of characters, in which each row is a separate string.

[88] What is the maximum number of labels permissible in a switch statement?

There is virtually no limit.

[89] What is the purpose of the switch statement?

The switch statement allows execution of its body to being at one of several

points, based on the value of an integer variable or expression.

[90] What is the role played by the break statement within a switch statement?

It causes the remaining statements in the body of the switch statement to be

skipped.

[91] What symbols are used to group together the statements comprising the body

of a switch statement?

The braces { and }.

[92] What keywords are always used in the body of a switch statement?

Case.

[93] What connection is there between the switch variable or expression and the

constants in the case labels?

Program control is transferred to the statement immediately following the case

label whose constant equals the value of the switch variable or expression.

[94] What role does the default label in a switch statement play?

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 52: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

If it is present, control transfers to the statement immediately following that label,

if the value of the switch variable or expression does not match any of the case

labels.

[95] In what order can the case labels be specified?

In any order that suits the logic of the program.

[96] Explain the action of the switch statement.

When the switch statement is encountered, the switch variable or exression is

evaluated. Program execution then continues at the case label whose constant is

equal to the value of the switch variable or expression. If no such case label

exists, execution continues at the default label if one is present. If neither a

matching case label nor a default label is present, the statements in the switch

statement body are skipped and execution continues at the statement following the

switch statement. If a break statement is encountered during execution of the

switch body, the rest of the statements in the body are skipped and execution

resumes after the switch statement.

[97] How can a string sorting technique be improved by resorting to pointer?

A pointer of any depth can represent the string. [limited only by the compiler]

instead of physically exchanging two strings when necessary, the pointers are

exchanged.

[98] What is the advantage of representing an array of strings by an array of

pointers to string?

If allows for easy moving of the strings by moving their pointers. It also allows

for the possibility that all the car array being pointed to may be of different

maximum lengths, thus, allowing for more efficient use of memory.

[99] What is another name sometimes given to arrays of type char?

Strings

[100] How is the end of a string recognized in C ?

By the null character ('\0')

[101] How is a literal accessed within a program?

By a pointer to the literal.

[102] What is the null string? What is its length?

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 53: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

The null string is an empty pair of double quotation marks@@. It is stored as null

character with no preceding characters. Its length is zero.

[103] What are static variables? Compare them with standard local variables?

A static variable is created when the program begins execution, and remains in

existence until the program terminates. A local variable declared, as static does

not disappear when the function ion which it is declared terminates.

[104] Explain the meaning of auto variable.

An auto variable comes to its existence when the function in which it is declared

is executed. It disappears when the function returns. The next time the function is

called, it is recreated.

[105] What is the role of the sprintf function ?

If stores its output in a string [ its first argument] instead of displaying or printing

it directly.

[106] What is the purpose of strcpy function ?

It stores one string, its second argument, into the array which is its first argument.

[107] How does the sscanf function operate ?

It operates exactly lilk the scanf function, except that it draws its input from a

string specified as its first argument instead from the keyboard.

[108] As a general concept, why is the validation of data is important?

When implemented to fullest, it assist the user in preventing errors frm occurring

in the input, alerts the user to the nature of the error, and also enables recovery

from the error to take place.

[109] What is meant by concatention? What function is used to achieve this

operation ?

Concatanation is the joining of two or more strings so that one begins where the

other ends. The strcat function concatenates its second argument to the end of its

first argument, which must be a variable string [an array].

[110] What function returns the length of a string?

The strlen function.

[111] What is an easy way of locating the end of a string?

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 54: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

Add the value returned by the strlen function to the pointer to the striog which

points to null character, the character that terminates the string.

[112] Under what circumstances is the malloc function useful?

When it is not known in advance how large an array will be and there is a need to

conserve memory.

[113] How does the malloc function operate?

The parameter of malloc function is the number of byets to be allocated. It returns

a pointer to a vacant area of memory of the specified size, or a value of 0 [null] if

the specifierd amount of memory cannot be allocated.

[114] What is the purpose of free function ?

It returns the memory allocated by the malloc function to the pool of free

memory. It is especially important to do this in program that place heavy

emphasis on memory allocation.

[115] What role does the size of operator play?

It returns the size in bytes [or, more generally char-sized units] of its operand.

[116] What is the min reason fro using structure?

In day-to-day applications, it is helpful to group together non-homogeneous data

into a single entity.

[117] What distinguishes an array from a structure?

Whereas the elements of an array are always of the same data type, the members

of a structure can be of different types.

118. What special keyword is used in defining a structure?

Struct

119. What is a template, and how does it relate to a structure ?

A template is a list of the members of a structure, alongwith their type

specifications enclosed in braces.

[120] What is a structure tag? What is its purpose?

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 55: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

A structure tag is a name associated with a structure template. This makes it

possible later to declare other variables of the some structure type without having

to rewrite the template itself.

[121] In what two ways can a structure variable be declared?

By preceding the variable name with the keyword struct and either [1] a

previously defined structure tag and / or [2] a template [optionally preceded by a

tag not previously defined.

[122] What is the connection between a structure and a new data type?

Associating a tag with a template makes it possible to use the tag [preceded by the

keyword struct] in the same way a type keyword is used, for example, to declare

variables or the types returned by functions.

[123] What is meant by an array of structures?

Each element is a structure in an array is called array of structure.

[124] In what sense can a structure be recursive?

It can contain other structures as members.

[125] What does nesting of structures mean?

It describes a situation in which a structure contains another structure as a

member.

[126] Narrate the restriction, which applies to the nesting of structures?

A structure cannot contain a member that is itself a structure of the same type as

the outer structure.

[127] What is a linked list?

A linked list is a group of structures in which the first structure points of the

second, the second points to third and so on.

[128] What must a structure include if it is to be a node in the linked list?

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 56: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

It must include a member that is a pointer to another structure of the same type.

[129] What is meant by C program being portable?

The program can be compiled and run on any c compiler with identical results.

[130] What, in general terms, is the role-played by C pre-processors?

It provides for the implementation of macros and conditional compilation.

[131] What symbol always precedes pre-processor directives?

The # sign.

[132] Where the line must all pre-processor directive begins?

The pre-processor must be able to distinguish between C identifiers and pre-

processor symbols. If, for example, a pre-processor constant has the same name as

a C variable, then the pre-processor replaces each occurrence.

[133] If pre processing is separate from compilation, why must identifiers in both be

named differently?

The pre processor must be able to distinguish between C identifiers and pre

processors symbols.

[134] How can a #define directive be continued to a new line?

The line that is to be continued with a backslash.

[135] Where can a pre-processor directive be written?

Anywhere at all in a program, so longas it starts in the starts in the first column of

a line and is not on the same line as another directive or C statement.

[136] Where can a preprocessor directive be split?

Whenever a blank space could safely be placed.

[137] What is macro, and what is it used for?

A macro is an abbrevation for a segment of code. It is useful whe n a sequence of

code is repeated often. In such a case, a macro saves the programmer typing

effort.

[138] What symbol is used to separate the arguments of a macro ?

The comma

[139] What can a macro argument consist of?

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 57: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

Any series of characters [except that the comma can be used only within

quotation mark or parenthesis.

[140] What is meant by a nested macro?

A macro whose definition include a reference to another macro.

[141] What role is played by the #undef directive?

It undefines a preprocessor symbol, meaning that it makes the preprocessor forget

that the symbol was defined. It is necessary if one wishes to change the value of a

preprocessor symbol.

[142] How is the #include directive used?

The file named in the directive is inserted into the program at the point where the

directive occurs.

[143] What are common uses of a header file?

To include various definitions that the programmer uses often; to include

definitions needed for certain operations; such as |/O; and to facilitate

communication between program files through the use of shared global variables.

[144] What is conditional compilation?

The including or excluding of certain program lines, depending on the value of

specified pre-processor symbols.

[145] State the reasons for using the #ifdef directive.

The #ifdef directive is used in order to pass certain lines of code of the compiler,

only if the specified pre-processor symbol is defined before the #ifdef directive is

encountered.

[146] How is the #ifndef directive used?

It passes lines of code to the compiler only if the specified pre-processor symbol

is not defined.

[147] When a C program is compiled, at what point is the pre-processor directive

processed?

The pre-processor runs first, before the program reaches the actual C language

compiler.

[148] What is characteristic of the #else and the #endif directive?

They are the only text permitted on the lines they occupy.

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 58: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

[149] How does the #if directive operate?

The #if directive is followed by an integer constant expression. If the expression

evaluates to a true [non-zero] value, the lines followed the directive are passed on

the compiler. Otherwise, the lines are omitted.

[150] What happens if a pre-processor symbol in the #if expression is underfed?

It is treated as having the value zero.

[151] What pre-processor symbol, if any, cannot be used in the expression of an #if

directive?

Symbol defined to be anything other than integer constant or expressions that

evaluate to integer constant.

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 59: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

MULTIPLE CHOICE

[1] C Language ha been developed by

[a] Ken Thompson [b] Dennis Ritchie

[c] Peter Norton [d] Martin Richards

[2] Language has been developed at

[a] Microsoft Corp. USA [b] At & T Bell Labs USA

[C] Borland International USA [d] IBM USA

[3] C Language come into existence in the year

[a] 1971 [b] 1957

[c] 1972 [d] 1983

[4] C is a

[a] Middle level language [b] 1957

[c] Low level language [d] None of above

[5] C can be used on

[a] Only DOS Operating System [b] Only UNIX Operating System

[c] Only Xenix operating system [d] All of above

[6] C programs are converted into machine level language with the help of:

[a] An Interpreter [b] A Compiler

[c] An operating system [d] None of above

[7] The real constant in c can be expressed in which of the following forms:

[a] Factorial form only [b] Exponential form only

[c] An operating system [d] None of above

[7] The real constant in c can be expressed in which of the following forms:

[a] Factorial form only [b] Exponential form only

[c] ASCII form only [d] Both fractional and exponential forms

[8] A Character variable can at a time store

[a] 1 character [b] 8 characters

[c] 254 characters [d] None of above

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 60: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

[9] The maximum width of a C variable name can be

[a] 6 characters [b] 8 characters

[c] 10 characters [d] 20 characters

[10] A C variable cannot start with

[a] An alphabet [b] A number

[c] A special symbol [d] Both B and C above

[11] Which of the following is allowed in a C Arithmetic Instruction

[a] [ ] [b] { }

[c] ( ) [d] None of above

[12] Which of the following statement is false?

[a] Each new C instruction has to be written on a separate line.

[b] Usually all C statements are entered in a small case letters.

[c] Blank spaces may be inserted between two words in a C statement.

[d] Blank spaces cannot be inserted within a integer variable.

[13] If a is an integer variable, a = 5/2 will return a value:

[a] 2.5 [b] 3

[c] 2 [d] 0

[14] Hierarchy of operators decides which operator

[a] is most important [b] is used first

[c] is fastest [d] operates an largest numbers.

[15] A expression contains relational operators, assignment operators and

arithmetic operators. In the absence of parenthesis, they will be evaluated in

which of the following order:

[a] assignment, relational , arithmetic [b] arithmetic, relational, assignment

[c] relational, arithmetic, assignment [d] assignment, arithmetic, relational

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 61: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

[16] The break statement is used to exit from:

[a] an if statement [b] a for loop

[c] a program [d] the main ( ) program

[17] A do-while loop is useful when we want the statements within the loop must

be executed:

[a] Only once [b] At-least twice

[c] More than once [d] None of the above.

[18] Arrays can be initialised provided they are

[a] Automatic [b] At-least twice

[c] More than once [d] None of the above.

[19] Arrays are passed as arguments to a function by

[a] value [b] reference

[c] both b & c [d] none of the above

[20] An array is a collection of

[a] different data types scattered throughout memory

[b] the same data types scattered throughout memory

[c] the same data types placed next to each other in memory

[d] different data types placed next to each other in memory

[21] Is this a correct array declaration ?

int num(25);

[a] Yes [b] No

[22] What is the difference between the 5@ in these two expressions? (Select the

correct answer)

int num [5];

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 62: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

num [5] = 11;

[a] first is particular element, second is type

[b] first is array size, second is particular element

[c] first is particular element, second is array size

[d] both specify array size.

[23] What will happen if you try to put so many values into an array when you

initialise is that the size of the array is exceeded?

[a] nothing [b] possible system malfunction

[c] error message from the compiler [d] other data may be overwritten.

[24] What will happen if you put too few elements in an array when you initialise

it?

[a] nothing [b] possible system malfunction

[c] error message from the compiler [d] elements with garbage values

[25] What will happen if you assign a value to an element of an array whose

subscript exceeds the size of the array?

[a] the element will be set to 0 [b] nothing, its done all the time

[c] other data may be overwritten [d] error message from the compiler

[26] When you pass an array as an argument to a function, what actually gets

passed ?

[a] address of the array [b] value of the elements of array.

[c] address of the first element of array [d] number of element of the array.

[27] Which of these are reasons for using pointers?

[a] To manipulate parts of array

[b] To refer to keywords such as for and if

[c] To return more than one value from a function

[d] To refer to particular programs more conveniently.

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 63: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

[28] If you do not initialize a static array, what will be the elements set to ?

[a] 0 [b] print( )

[c] scanf( ) [d] puts ( )

[30] Given the statement, maruti.engine.balls-25; which of the follwing is true?

[a] structure balls is nested within structure engione

[b] structure engine is nested within structure maruti

[c] structure maruti is nested within structure engine

[d] structure maruti is nested within structure balls.

[31] To receive the string "We have got the guns, you get the glory" in an array char

str[100] which of the following functions would you use?

[a] scanf(“%s”, str); [b] gets (str);

[c] getche(str); [d] fgetchar(str);

[32] Which function would you use if a single key is to be received through the

keyboard?

[a] scanf( ); [b] gets( ) ;

[c] getche( ) ; [d] getchar( );

[33] Ifan integer is to be entered through the keyboard, which function would you use?

[a] scanf( ); [b] gets( ) ;

[c] getche( ) ; [d] getchar( );

[34] If a character string is to be received through the keyboard which function would

work faster?

[a] scanf( ) ; [b] gets ( ) ;

[35] The format string of a printf( ) function can contain :

[a] characters, conversion, specifications and escape sequences

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 64: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

[b] characters, integers and floats

[c] strings, integers and esape sequence

[d] Inverted commas, percentage sign and backslash character

[36] A field width specifier in a print( ) function :

[a] Controls the margins of the program listing

[b] specifies the maximum value of a number

[c] controls the size of type used to print numbers

[d] specifies how many columns will be used to print the number.

[37] The macro FILE is defined in which of the following files:

[a] stdlib.h [b] stdio.c

[c] io.h [d] stdio.h

[38] On opening a file for reading which of the following activities are performed:

[a] The disk is searched for existence of the file.

[b] The file is brought into memory

[c] A pointer is set up which points to the first character in the file.

[d] All of above.

[39] Pick the odd one out:

[a] a= a+ 1; [b] a +=1;

[c] a++; [d] a=+1;

[40] The order of three parts of a loop expression in the for loop should be:

[a] Initialization, test, increment [b] test, initialisation, increment

[c] increment, test, initialization

[41] What is a preprocessor directive :

[a] a message from compiler to the programmer

[b] a message from compiler to the linker

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 65: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

[c] a message from programmer to the preprocessor

[d] a message from compiler to the microprocessor

[42] A header file is:

[a] a file that contains standard library functions

[b] a file that contains definitions and macros.

[c] a file that contains user defined functions.

[d] a file that is present in current working directory.

[43] It is necessary to declare the type of a function in the calling program if

[a] the function returns an integer

[b] the function returns a non-integer value.

[c] the function is not defined in the same file.

[d] none of the above.

[44] The declaration void function1 [int] indicates the function1 is a function

which

[a] has no arguments [b] returns something

[c] both a and b [d] none of the above.

[45] Recursive functions are executed in a

[a] Last in first out order [b] First in first out order

[c] parallel fashion[d] any one of the above.

[46] When a function is recursively called, all automatic variables :

[a] are initialised during each execution of the function.

[b] are retained from the last execution

[c] are maintained in a stack

[d] none of the above.

[47] A static variable is one

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 66: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

[a] which cannot be initialised.

[b] which is initialised once at the commencement of execution and cannot be

changed at run time.

[c] retains its value throughout the life of the program

[d] which is same as an automatic variable put is placed at the head of the

program.

[48] An external variable is one

[a] which is globally accessible by all functions.

[b] has a declaration "extern" associated with it when declared within a function.

[c] will be initialised to 0 if not initialised.

[d] all of above.

[49] A switch statement is used to :

[a] switch between functions in a program.

[b] switch from one variable to another variable.

[c] to choose from multiple possibilities which may arise due to different values

of a single variable.

[d] to use switching variables.

[50] The statement #include<math.h> is written at the top of a program to

include:

[a] the beginning of the program.

[b] the program does heavy mathematical calculations

[c] that certain information about mathematical library functions are to be

included at the beginning of the program.

[d] none of the above.

[51] The function fprintf is used in a program.

[a] when too many printf calls have been already used in the program.

[b] in place of printf, sice printf uses more memory

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 67: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

[c] when the output is to be printed on to a file.

[d] when the type of the variables to be printed are not known.

[52] The declaration unsigned u indicates

[a] u is an unsigned character [b] u is an unsigned integer.

[c] u is a character [d] none of the above.

[53] A declaration "short int" is used for variables

[a] which have a short duration in a program

[b] which have short names

[c] which may require less storage than normal integers.

[d] all of above.

[54] Which of the following 'C' type is not a primitive data structure?

[a] int [b] float

[c] char [d] none of the above.

[55] The library function exit( ) causes an exit from

[a] the loop in which it occurs [b] the block in which it occurs

[c] the function in which it occurs [d] none of these.

[56] The getch( ) library function

[a] returns a character when any key to pressed

[b] returns a character when enter is pressed

[c] returns and displays a character on the screen when any key is pressed.

[d] none of the above.

[57] A default argument has a value that

[a] may be supplied by the calling program or function

[b] related data items and variables

[c] integers with user defined names

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 68: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

[d] none of them.

[58] A structure brings together a group of

[a] items of the same data type [b] related data items and variables.

[c] integers with user defined names. [d] none of them.

[59] The &&(and) operators

[a] compare two numeric values [b] combine two numeric values

[c] compare two Boolean values [d] perform none of the above.

[60] The break statement causes an exit

[a] to the innermost loop

[b] only from the innermost loop or switch

[c] none of the above.

[61] In a for loop with a multi statement loop body, semicolons should appear ion

following:

[a] the for statement itself.

[b] the crossing brace in the multiple statement loop body.

[c] each statement within the loop body and the text expression.

[d] none of the above.

[62] When an array name is passed to a function, the function

[a] Accesses exactly the same array with the same name as the calling program.

[b] Accesses a copy of the array passed by the program

[c] Refers to the array using the same name as that used by the calling program

[d] Does none of the above.

[63] The first element in a string is

[a] the name of the string[b] the first character in the string

[c] the length of the string [d] none of the above.

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 69: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

[64] A pointer is

[a] Address of a variable.

[b] An indication of the variable to be accessed next.

[c] a variable for storing address.

[d] None of the above.

[65] If an array is used as a function argument, the array is passed

[a] by value [b] by reference

[c] None of the above [d] call by name.

[66] A data file must be closed using

[a] fprintf( ) function [b] fclose( ) function

[c] Exit function [d] none of the above.

[67] The statement FILE *fpt,

[a] defines a pointer to pre-defined structure type FILE

[b] defines a pointer to user defined structure type FILE

[c] defines a pointer to pre-defined data type FILE DESCRIPTOR.

[d] none of the above.

[68] The function fgets and fputs

[a] reads and write strings from or to data files

[b] reads and write strings from or to input / output stream

[c] reads and write records from or to daa files.

[d] none of the above.

[69] When one-dimensional character array of unspecified length is assigned an initial

value

[a] an arbitrary character is automatically added to the end of the string.

[b] '10'is added to the end of string.

[c] length of the string is added to the end of the string

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 70: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

[d] any of the abov.

[70] In order to check whether an input number is vowel or not, an efficient multiway

decision making routine can be written using

[a] while loop [b] switch

[c] if-then-else [d] none of the above

[71] Enumeration variables can be used in

[a] search statement [b] break statement

[c] preprocessor commands [d] All of the above

[72] #define preprocessor command can be used for defining

[a] macros [b] for loop

[c] symbolic constants [d] both [a] and [c]

[73] Which of the following statements is true after execution of the program.

Int a[10], I, *p;

A[0] = 1;

A[1] = 2;

P = a;

(*p) ++;

a. a[0] = 2 b. a[1] = 3

c. a[1] = 2 d. all

[74] Consider the following program fragment

main ( )

{

int a, b, c';

b = 2;

a = 2* (b++);

c=2* (++b);

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 71: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

}

which one of the given answer is correct ?

a. a = 4, c = 6. b. a = 3, c = 8.

c. b = 3, c = 6. d. a = 4, c = 8.

[75] Given the following program fragment, which one of the alternatives is correct ?

main ( )

{

char status;

int balance;

balance = 1000;

status = (balance >= 1000)? ‘C’: ‘O’ ;

}

a. status = ‘O’ b. status = ‘C’

c. status = O; d. status = NIL

[76] How many times will the printf statement be executed ?

main ( )

int n;

n = 10;

while (n < 10)

{

printf (“hello!”);

--n;

}

}

a. never b. once

c. 10 d. 9

[77] If the following loop is implemented

main ( )

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 72: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

{

int num;

num = 0;

do

{

--num;

pritnf(“%d”, num);

num++ ;

}while (num >=0)

}

a. the loop will run infinitely many times.

b. the program will not enter the loop.

c. there will be a compilation error reported.

d. a run time error will be reported.

[78] What is the final value of digit ?

main ( )

{

int digit;

for (digit = 0; digit <=9; ++digit)

{

print{“%d\n”, digit);

digit = 2* digit;

-- digit;

}

}

a. 10 b. -1

c. 17 d. 16

[79] What is the final value of sum ?

main ( )

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 73: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

{

int sum = 1;

for (;sum <=9;)

print(“%d\n”, ++sum);

}

a. 10 b. 9

c. 11 d. none of the above

[80] What is the value of average after the following program is executed ?

main ( )

{

int, sum, index;

index = 0;

sum = 0;

for (; ;)

{

sum = sum + index ;

++ index;

if (sum >= 100) break;

}

average = sum/index;

}

a. 91/4 b. 91/13

b. 105/15 c. 105/14

[81] What is the output of the following program ?

main ( )

{

int x, y, z;

X = 2

Y = 1;

Z = 1;

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 74: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

If (x > y + z)

Print(“Hello\n”);

Else if (x < y + z)

Printf (“Hey!n”);

Else

Printf (“Hey!n”);

}

a. Hi ! b. Hello !

c. Hey ! d. None

[82] What is the value of variable POLYGON ?

main ( )

{

int POLYGON, L, B;

L = B = 2;

POLYGON = (L = = B) ? 1:0:

}

a. 0 b. 1

c. 2 d. None of the above

[83] The output of the above program will be

#define two (×) 2* ×

# define ddouble (x) x+x

main ( )

{

int num, sum, product;

num = 1;

sum =-two (num); -sum;

product = -dddouble (num);

print(“%d%d\n“, sum, product);

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 75: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

a. 0 0 b. 0 1

c. 1 1 d. 1 0

[84] The following program fragment

main ( )

{

int sum, index;

index = 50;

while (index >=0)

{

}

a. will give a run time error b. wil give a compilation error

c. will give a linking error d. none of the above

[85] What is the output of teh following program ?

main ( )

{

int B, X, Y, Z;

X = 1;

Y = 2;

Z = 3;

if ((X > 1) (Y > 1))

if (Z > 1)

print ("O.K.=n“) ;

else break ;

if (X > 1) && (Z >3))

printf (“Bye\n”);

print(“Hello“) ;

}

a. O.K. Bye b. Bye

c. O.K. d. Hello!

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 76: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

(86) What is the output of this program ?

main ( )

{

float balance, loan ;

balance = 1000.0;

loan = balance/10;

if (balance > 500) (loan < 500)

printf(“good account=n”);

if(balance < 500) (loan < 500)

printf(“caution !\n”);

}

a. good account b. caution

b. good account caution d. good account caution.

(87) The following lines, if included in a program, will cause one of the following

errors. Indicate the correct one.

{double c;

scanf(“%c”, c);

}

a. Runtime error b. Compilation error

c. Typedf error d. No error

[88] If the following variable are set to the values as shown below, then what is the

value of the expression following it ?

answer = 2;

marks = 10;

!(answer > 5) (marks > 2))

a. 1 b. 0

c. -1 d. 2

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 77: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

[89] What is the following program doing ?

main ( )

{

int digit = 0;

do

{

print(“%d\n”, digit++);

while (digit <=9);

}

a. Adding 9 integers b. Adding integers from 1 to 9

c. Displaying any 9 integers d. Displaying integers from 1 to 9

[90] Consider the program fragment

switch(choice) {

case 'R' : print(“RED”);

case 'W' :printf(WHITE");

case 'B' : printf(“BLUE”);

default : printf (“ERROR”);

break ;

}

what would be the output if choice = 'R' ?

a. RED b. RED ERROR

c. RED WHITE, BLUE ERROR d. RED, WHITE, BLUE

[91] If c is a variable initialised to 1, how many times will the following loop be

executed ?

while ((c > 0) && (c < 60)) {

loop body

c ++; }

a. 60 b. 59

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 78: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

c. 61 d. 1

[92] If x and y are variable are declared as double x = 0.005, y = -0.01; What is the

value of cell (x + y), where cell is a function to computer celling of a number ?

a. 1 b. 0

c. 0.005 d. 0.5

[93] The for statement which can precede a loop to be executed 50 times or till a

Boolean variable “found” becomes falase is give by

a. for (i = 0; i <= 50 found == false; i++)

b. for (i = 0; i < 50 found = = true; i++)

c. for (i = 1; i < = 50 found = = true; i++)

d. none of the above

[94] Consider the following declarations

typedef struct {

char name [20];

char middlename [5];

char surname [20];

} NAME

NAME class [20];

Here,

a. class is an array of 20 characters only

b. class is an array of 20 names where each name consists of a name, middlename

and surname

c. class is a new type

d. none of the above

[95] What would be the values assigned to a,b,c if the statement scanf(“%d %d %d”,

&a, &b, &c) is extended with input data item 123456 ?

a. a = 12, b = 34, c = 56

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 79: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

b. a = 1, b = 2, c = 3

c. a = 123456 and nothing is assigned to b and c

d. a and b are not assigned anything, c = 123456

[96] What would be the values assigned to a, b and c is the statement scanf(“3d, %3d,

%3d”, &a,&b, &c) is executed with input data as 1234b5678b9 (b denotes

blank) ?

a. a = 123, b = 4, c = 567 b. a = 123, b = 567, c = 9

c. a = 123, b = 456, c = 789 d. a = 1234, b = 5678, c = 9

[97] What would be the values of I, x and c if scanf(“3d. %5f. %c”, &I, &x, &c) is

executed with inpout data 10b256.875T ?

a. i = 10, b = 56,875, c = T b. i = 100, b - 256.87, c = T

c. i = 010, b = 256.87 c = '5' d. i = 10, b = 256.8, c = '7'

[98] What would be the assignments if char s[100]; int d; float f; scanf(“%s, %*f, %f”,

&d, &f) is executed with input data fastener b12345b5

a. s = “fastener”, d = 12345, f = 0.05 b. s = “fastener”, d = 123*45, f = 0.05

c. s = “fastener”, f = 0.05 d. s = “fastener”, d = 0.05

[99] What would be the output of the following program fragment ?

{

int i = 12345;

float × = 145.678'

printf(“%3d, %d, %8d”, i,i,i);

}

a. 123 123 123 b. 12345 12345 12346

c. 12345 d. 1 2 3

[100] In the following statement

fprint(fpt, “%n”, i) the variable fpt is

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 80: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

a. a character variable b. arbitrarily assigned a value

c. a pointer to a file d. a special kind of variable called “file”.

[101] Consider the following declaration

struct list {

int x';

struct list *next;

}*head;

The statement head.× = 100

a. assigns 100 to one element of the structure list

b. creates a node of type list and assigns a value to x

c. creates a head of the list

d. is an erroneous statement.

[102] How many times will the following loop be executed ?

cl = 'a';

while (c) > = 'a' && c1 <='z')

{

c1 ++;

}

a. 25 b. 26

c. 0 d. 1

[103] What is the following function doing ?

test (a,b)

int a, b;

{

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 81: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

int z = (abs(a) >=abs(b)) ? a:b;

return (z):

}

a. finds the maximum of a and b;

b. returs the minimum of a and b;

c. returns the member whose absolute value is largest

d. none of the above

[104] What will be the output of the following program ?

{

int i = 1234; i=0177, k=0xa08c;

printf(“%8d, %80x\n”, i, k);

a. 1234 1777 a08c b. 1234 |abc a08c

c. 00001234 01aa ax d. 1234 0777 ao8o

[105] What is the following function doing ?

main ( )

char line [80];

gets (line);

puts (line);

}

a. prints horizontal straight lines an screens

b. prints 80 vertical lines on screen

c. reads in a line of 80 characters

d. reads and prints lines composed of characters

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 82: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

[106] if I, j, k are integers, the scanf function to enter i, j, k such that i is

decimal, i is octal and k is hexadecimal would be

a. scanf(“%x, %x, %8x” i, j, k) b. scanf(“%d, %o, %x”, i, j, k)

c. scanf(“%d, %o, %x” &I, &j, &k) d. scanf(“%d, %8d, %16d”, &i,

&j, &k)

[107] How many times will the following loop be executed if the input data

item is 01234 ?

while (c = getchar( )!) {

a. infinitely b. never

c. once d. 5 times

[108] What would be the value of c ?

{

int c;

float a, b;

a = 245.05;

b = 40.02;

c = a + b;

[109] What would be the value of i and k ?

{

int i, j, k;

I = 5;

I = 2 * j/2;

K = 2* (i/2);

}

a. i = 5, k = 5 b. i = 4, k = 4

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 83: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

c. i = 5, k = 4 d. 4

[111] How many times will be the following loop be executed ?

{

x = 5;

if (x = 1) {

x++;}

}

a. never b. once

c. 5 times d. infinitely many times

[112] If an integer occupies 5 bytes and a character occupies 1 bytes of

memory, each element of the following structure would occupy how

many bytes ?

struct name {

int age ;

char name [20];

}

a. 5 b. 24

c. 2] d. 22

[113] A short integer occupies 2 bytes, an ordinary integer 4 bytes and a

long integer occupies 8 bytes of memory. A structure is defined as

struct TAB {

short a ;

int b;

long c ;

SHRI SUNSHINE GROUP OF INSTITUTIONS

Page 84: Programming In C Quan Book

FACULTY OF COMPUTER SCIENCE

}

TABLE [10];

Then the total memory requirement for TABLE is

a. 14 b. 140

c. 40 d. 24

[114] The library function sqrt operates on a double precision argument. If, i

is an integer variable, which one of the following calls would

correctly compute sqrt(i) ?

a. sqrt ((double)i) b. (double) sqrt(i)

c. (double)(sqrt(i)) d. sqrt(i)

[115] Consider a part of a loop as shown below.

for (i = 0; i <= 10000; i ++)

{ :

:

If (error < 0.005) break :

}

The above loop will

a. always run for 10,000 times b. will never run for 10,000

times

c. may or may not run for 10000 times d. none of the above.

SHRI SUNSHINE GROUP OF INSTITUTIONS