# CHAPTER 11 ARRAYS

Q
1
. What is an array?
A structured data type consisting of a group of elements, each element of the same
type and same name.
Q
2
. Why do we need arrays?
We need arrays to store a group of elements as a single data structure. This helps
to reduce the storage space and makes the accessing of elements easier.
Q
3
. How are arrays different from normal variables?
Arrays are different from normal variables in that they are a group of elements and
not a single element .It also has an index with the help of which each element can
be accessed.
Q
4
. Can an array store more than one type of variable?
No, an array can store only one type of data.
Q
5
. What is the subscript of the first element of an array?
The subscript of the first element of an array is zero.
Q
6
. Give one characteristic of the subscript of an array.
The subscript starts from zero and must be an integer.
Q
7
. What are the data types which can be used to represent an array subscript?
Only Integers.
Q
8
. Why should an array subscript not be of a float type?
Because it has to identify each element of the array uniquely and indices cannot be
fractional numbers.
Q
9
. What is the relationship between the value of the subscript and the value of the array
element?
The value of the subscript denotes the position of the element of the array.
Q
10
. What are the different types of arrays?
One Dimensional array
Two Dimensional arrays
Multi Dimensional array
Q
11
. Define a one-dimensional array.
A one-dimensional array is a structured collection of elements that can be accessed
individually by specifying the position of an element with a single index value.
Q
12
. Give the syntax of a one-dimensional array declaration.
The general form of array declaration is:
Data_type Array-Name [ SIZE ];
Q
13
. Write an array declaration to store the data of 1000 integers in the array.
int a[1000]
Q
14
. How are one-dimensional arrays initialized when they are declared?
int a[4] = {1,2,3,4}; In this declaration, a[0] is initialized to 1, a[1] is initilialized to
2 and so on.
Q
15
. Is it necessary to initialize all elements of an array in a program?
No it is not necessary to initialize all elements of an array in a program.
Q
16
. What values are assigned to the locations of an array when they are not initialized?
If the array is of integer type then the default value assigned to the locations of the
array are all zero.
Q
17
. How are individual elements of a one-dimensional array accessed?
The individual elements of a one-dimensional array accessed with the help of the
index.
Q
18
. Can the entire array be processed in a single statement?
Yes with the help of a for loop.
Q
19
. Mention the difference between an integer array and a character array.
Integer array stores only integers and has 2 bytes in each element whereas
character array stores only characters and has one byte.
Q
20
. Define a two-dimensional array.
A two dimensional array is used to represent elements in a table with rows and
columns, provided each element in the table is of the same type.
Q
21
. Give one difference between a one-dimensional and two-dimensional array.
One–dimensional arrays consist of only one row of elements but two– dimensional
arrays consist of a table of rows and columns each consisting of some elements.
Q
22
. Give the syntax of a two-dimensional array declaration.
Two-dimensional array is declared in exactly the same way as a
one-dimensional array, except that sizes must be specified for two dimensions. The
general form of array declaration is:
Data_type array_name [ RSIZE ][ CSIZE ];
Q
23
. Write an array declaration to store the data of 1000 students and the marks of 5
subjects for each student in a two-dimensional array.
int [1000] [5];
Q
24
. How are two-dimensional arrays initialized when they are declared?
int matrix[2][3]={1,2,3,4,5,6};
Q
25
. How are individual elements of a two-dimensional array accessed? Individual
elements of a two-dimensional array can be accessed with the help of two subcsriots.
Q
26
. What are multi dimensional arrays?
Collection of elements, all of the same type, ordered on N dimensions. Each
element is accessed by N indices, each of which represents the element‟s position
within that dimension.
Q
27
. Give the general form of the declaration of a multi-dimensional array.
The general form of the multidimensional array is:
type array_name[s1][s2][s3]......[sm];

Q
1
. What are arrays? When do we use them?
Array is a structured data type consisting of a group of components, each
component of the same type .The entire group is given a name which becomes the
array name. We use them when we want to store a set of elements all of the same
type and the accessing of these elements have to be easy.
Q
2
. How do you declare an array? Explain with a suitable example.
We declare an array by giving the type of its elements, its name, and the number of
elements. The general form of array declaration is:
Data_type Array-Name [ SIZE ];

Example: float height[5];
int testscore[10];‟
The first declaration declares an array whose name is “height” ,elements are of type
float and can contain a maximum of 5 elements. The second declaration declares
an array whose whose name is “testscore” ,elements are of type integer and can
contain a maximum of 10 elements.
Q
3
. Explain one-dimensional array.
One-dimensional array is a structured collection of elements, all of the same
type, that is given a single name. Each element is accessed by an index that
indicates the component‟s position within the collection.
Q
4
. Explain two-dimensional array.
A two dimensional array is a collection of elements, all of the same type, structured in
two dimensions. Each element is accessed by a pair of indexes that represent the
element‟s position in each dimension.
Q
5
. Explain Multi-dimensional array.
Multi-dimensional array is a collection of elements, all of the same type, ordered
on N dimensions. Each element is accessed by N indexes, each of which represents
the element‟s position within that dimension.
Q
6
. What are subscripts? What are the rules for applying values to subscripts?
Subscripts denote the position of each element within the array.The subscripts of
an array variable may be
1. Integer constants.
2. The subscript value cannot benegative.
3. Subscripts can be integer variables or integer expressions.
Q
7
. Give the syntax of declaring a one-dimensional array.
We declare an array by giving the type of its elements, its name, and the number of
elements.The general form of array declaration is:

Data_type Array-Name [ SIZE ];

Where Data_type describes what type of data is stored in each element of the
array. Array elements may be of almost any type (int, float, char, double, struct,
pointer or union) SIZE is an integer expression composed of only literal or named
constants. This expression, which specifies the number of elements in the array,
must have a value greater than 0. If the value is n, the range of index values is 0
through n-1, not 1 through n. For example,

Example: float height[5];
int testscore[10];
Q
8
. Is it possible to declare and initialize an array in C simultaneously? If so, how?
A special feature of arrays is that they can be initialized when they are declared.
This is done by following the array name and dimension with an equal sign,
followed by a pair of braces. These braces contain a series of constant values
separated by commas.

Example : int marks [5] = {56, 67, 15, 98, 12};

In this declaration, marks [0] is initialized to 56, marks [1] is initialized to 67 and so
on. There must be at least one initial value between the braces.
Q
9
. Why is it necessary to use arrays to perform the operations of sorting and searching?
Arrrays are useful in performing sorting and searching because the elements of an
array are stored based upon an index value. This index makes the identification
and positioning of the elements to be easy which in turn will make the searching
and sorting easier.
Q
10
. Write a program fragment to show the input and output operations of a one-
dimension array.
#include <stdio.h>
main()
{
int a[10];
int i,n;
printf(“\nInput number of elements “);
scanf(“%d”,&n);
printf(“\nInput array elements\n”);
for(i=0; i<n; i++)scanf(“%d”,&a[i]);
printf(“\array elements\n”);
for(i=0; i<n; i++)printf(“%d\t”,a[i]);
}
Q
11
. How do you declare a two-dimensional array?
A two dimensional array is used to represent elements in a table with rows and
columns, provided each element in the table is of the same type. An element in a
two-dimensional array is accessed by specifying the row and column indices of the
item in an array.The general form of array declaration is:

Data_type array_name[Const-1][ Const2 ];

Example: Consider the following declaration
int a[10][10];
a is a two dimensional array which contains 10 rows and 10 columns.
Q
12
. Write a program fragment to show the input and output operations of a two-
dimensional array.

Consider the following declaration:
int a[3][3];
The following for loops would read in 9 numbers and store them in the array a.
for(row=0; row<3;row++)
for(col=0; col<3;col++)
scanf(“%d”,&a[row][col]);
The following for loops would print matrix elements in the matrix format.
for(row=0; row<3;row++)
{
for(col=0; col<3;col++)
printf(“%d\t”,a[row][col] );
printf(“\n”);
}
Q
13
. How do you declare a Multi-dimensional array?
Multidimensional arrays are defined in much the same manner as one dimensional
and two dimensional arrays, except that a separate pair of square brackets is required for
each dimension of elements that are defined.The general form of the multidimensional
array is:

type array_name[s1][s2][s3]......[si];

where si is the size of the ith dimension.
Example : int a[3][10][5];

PART C FIVE marks questions Long Answer Questions

1. What are the advantages of arrays over normal variables explain with examples?
2. Input the total sales of a month into a one-dimensional array for 20 salesmen.
Calculate the total sales and identify the salesman who has sold the most.
3. Write a program to generate the fibonacci series using arrays.
4. Two friends play 15 games of football in a season. Input the data of each friend in a
separate one-dimensional array and find: (a) The
total goals scored by each friend. (b) The highest
goal scored and in which match. (c) The match in which
both the friends did not score any goals.
5. A student writes a test every month in a college. Input the data for the student and
find:
(a) The month in which he has scored the highest marks. (b)
The lowest marks scored by the student.
6. Give an array declaration that identifies the amount of rain every day in the month
of September. Write a program segment that calculates the total rain for the entire
month.
7. Write a program to store data in 10 rows and 10 columns and find the total of all
data in the diagonal positions.
8. Write a program to find the product of two matrices.
9. Write a program to re-arrange the elements of each row of the above matrix in
descending order?
10. Write a program to find the norm and trace of a matrix. (Norm is the square root of
the sum of the squares of all the elements of the matrix)
11. Write a program to find the product of two matrices of different orders.
12. Write a program to find the sum of two matrices.

PART D TEN marks questions Very Long Answer Questions

1. What is an array? Mention different types of arrays and explain their usage
with a suitable example.
2. Explain binary search operation with a suitable program.
3. Explain any one sorting technique with a suitable program.
4. Explain the methods of declaring and initializing one dimensional and two
dimensional arrays with suitable examples.
5. Write a program to perform any two matrix operations(Addition, Subtraction
or Multiplication)
6. Write a program to check a matrix is symmetric.
7. Write a program to read a set of numbers and store it on the one dimensional array
A, copy the elements in the order array B in the back direction, find the sum of
individual elements of an array A and B store direction, find the sum of individual
elements of an array A and B store the results in an array C and display all the
three arrays.
8. Write a program to sort the given array and insert a given item value in the proper
place using binary search.
9. Write a program to find the transpose of the following matrix and find A*A'.

9 10 19 12
A =
Q
1
. What is a string?
A string is a sequence of characters terminated by a NULL ('###BOT_TEXT###') character.
Q
2
. What is the significance of the NULL character?
The NULL ('###BOT_TEXT###') character signifies the end of the string.
Q
3
. How is the end of a string is recognized in C?
The end of the string in recognized in C by looking for the NULL character.
Q
4
. How do you declare a string variable?
A string is declared as an array of character type, by specifying its name, and the
number of characters to be contained in it.For example ;
char name[20];
Q
5
. Which is the header file, which should be included while performing string operations
in a program?
string.h
Q
6
. What is the length of the string “BANGALORE”?
9. The NULL character is not included in a string's length.
Q
7
. What is a null string?
A null string is one whose length is zero.
Q
8
. What function returns the length of a string?
strlen() function.
Q
9
. What is the purpose of the strlen( ) function?
It returns length of a string.
Q
10
. What is the purpose of strcpy( ) function?
It copies the contents of one string to another.
Q
11
. How do you compare two strings in C?
Two strings are compared using the strcmp( ) function.
Q
12
. What is the purpose of strcmp( ) function?
It is used to compare two strings in C.
Q
13
. What is meant by concatenation?
Concatenation is the process of joining two strings together.
Q
14
. What function is used to concatenate two strings?
strcat() function
Q
15
. What is the purpose of strrev( ) function?
It reverses a given string.
Q
16
. What is the purpose of strlwr( ) function?
This function converts all characters in a string from uppercase to lowercase.
Q
17
. What is the purpose of strupr() function?
This function converts all characters in a string from lowercase to uppercase.
Q
18
. What is the purpose of strcmpi() function?
This function compares two strings but is not case sensitive.
Q
19
. Can a list of strings be stored within a two dimensional array?
Yes it can be stored.

Q
1
. What is the difference between a character and a string? Explain with an example.
A character is a single character enclosed within single quote like „a‟, „o‟. But a
string is a set of characters stored in consecutive locations in memory and
terminated by the NULL character. For example, “SUMUKHA”.
Q
2
. How is a string stored in an array in C?
It is terminated by the NULL character, which has the value 0 and is written in C
as '###BOT_TEXT###'. For example,

C O M P U T E R ###BOT_TEXT###
Q
3
. How do you assign a value to a string variable?
Assignment of values to strings can be done by the following three methods of
initializations:
1. char name [5] = “PCMC”; /* NULL terminator is automatically added */
2. char name[ ] = “PCMC” /* NULL terminator is automatically added */
3. char name[9]= {„P‟,‟C‟,‟M‟,‟C‟,'###BOT_TEXT###'};
Q
4
. What is a null string? What is its length?
The null string is an empty pair of double quotation marks (""). It is stored as a
null character with no preceding characters. Its length is zero.
Q
5
. What are the different methods of inputting strings?
To read a string, we use a standard I-O library function scanf() function.
i. scanf ( ) reads formatted input from the standard input. We can read values
into a string with scanf ( ) function using %s formatting specifier:
scanf (“%s”, name);
ii. gets() function accepts an entire line of input from the standard input
device, appends a null character „###BOT_TEXT###‟ at the end of the string.
gets(name);
Q
6
. What are the different methods of output a string?
There are two methods to output a string. They are
i. puts( ) which prints unformatted output and
ii. printf( ) which prints formatted output.

Q
7
. What is the difference between scanf( ) and gets( ) function?
The scanf( ) function accepts characters one at a time until either a blank space or
a newline character is encountered.
The gets( ) function accepts characters one at a time until a newline character is
encountered.
Q
8
. Explain the formatted printf( ) function with an example?
Generally printf( ) function has the following format:
Syntax : printf(“formatcontrol string”,value_1,value_2,value_3,..);
C allows the programmer to explicitly specify field widths for each output data. The
% symbol in a format control expression may be followed by an optional format
modifier, which may specify the number of spaces in which the data must be
output, and whether the output should be left or right justified within these spaces.

Example: To output the following string:
Computer

right justified in a field of width 25 spaces, use the following printf( ) function.
printf(“%15s”,”Computer”);
Q
9
. What is the output of the following program?
main( )
{
char name[ ]="COMPUTER";
printf(""%s",name);
name[5]='###BOT_TEXT###';
printf(""%s",name);
}
Output is
COMPUTER, COMPU
Note that the printf statement will recognize the string only until the NULL
terminator.
Q
10
. What are the operations possible on strings?
i. Concatenation,
ii. Copying,
iii. Reversing,
iv. Comparing and Case conversion
Q
11
. Give any four library functions, which can be used with strings.
i. strcmp()
ii. strlwr()
iii. strupr()
iv. strrev()
Q
12
. If array1 and array2 are dimensioned as follows :
char array1[10], array2[10];
and array1 has been initilized, what is the effect of the following.
array1=array2;
A syntax error is displayed by the compiler. One array cannot be assigned to
another using the assignment operator. Each element must be assigned
individually.
Q
13
. What is meant by concatenation? What function is used to achieve this operation?
Concatenation is the joining together 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)
Q
14
. What are the possible values the strcmp function can return, and what do they
mean?
If strcmp returns 0(zero) it means that its two arguments are identical. A negative
value indicates that the first argument is alphabetically less than the second. A
positive value means the first argument is alphabetically greater than the second.
Q
15
. What is the difference between strcmp( ) and strcmpi( ) functions?
strcmp( ) compares two strings and is case sensitive and strcmpi is also similar to
strcmp but is case insensitive.
Example : strcmp(“ABC”,”ABC”) returns 0.
strcmp(“ABC”,”abc”) returns -32.
strcmpi(“ABC”,”abc”) returns 0.
Q
16
. What is the difference between strlwr( ) and strupr( ) functions?
strlwr() converts uppercase letters into lowercase letters but strupr( ) converts
lowercase letters into uppercase letters.
Example : strlwr(“ABC”) returns “abc”.
strupr(“abc”) returns “ABC”.
Q
17
. What is the difference between strcpy( ) and strcmp( ) functions?
strcpy( ) function copies one string into another but strcmp( ) compares two strings.

Example : strcpy(str,”ABC”) assigns “ABC” to str char array.
strcmp(“ABC”,”abc”) returns -32.
Q
18
. What do we mean by an array of strings? Explain.
An array of strings is a 2-D character array which consists of rows each of which
stores strings and there can be many such rows in a single array.

Example : A B C D E F ###BOT_TEXT###
P Q R S T ###BOT_TEXT###

PART C FIVE marks questions Long Answer Questions

1. Explain the method of creating and using strings with a suitable programming
example.
2. Explain the use of the various library functions associated with strings.
3. Write a C program to count number of alphabets in a string.
4. Write a C program to check whether a string is palindrome.
5. Write a C program to input a word and output all possible combinations of it.
6. Write a C program to arrange the names of five fruits in the alphabetical order.
7. Write a program to arrange all the alphabets in a string in the alphabetical order.
(For example STRING is a word, GINRST is the arranged string).

CHAPTER 12 FUNCTION & CHAPTER 13 USER DEFINED
FUNCTIONS
Q
1
. What is a function?
A function is a named unit of a group of program statements designed to perform a
specific task and returns a single value.
Q
2
. What are the different types of functions supported in “C” language?
C supports two types of functions. They are :
i. Built-in or library functions.
ii. User defined functions.
Q
3
. What are library functions?
Function which are defined by the C compiler are called library functions.
Q
4
. Give any two examples of library functions.
sqrt( ) and strcpy( )
Q
5
. What is a user-defined function?
A function declared and defined by the user is called a user-defined function.
Q
6
. Explain one reason why functions should be used.
If there is a portion of the program, which is to be repeated in a number of places in
the program, a function may be used to avoid rewriting the same sequence of code
at two or more, locations in the program.
Q
7
. What do we mean by a calling function?
Calling a function means transferring control from calling function to called
function by specifying the name of the function and optionally passing parameters.
Q
8
. What is a called function?
A named unit of a group of program statements which is called from the calling
program is called a called function.
Q
9
. How is a function invoked?
Its name is specified, followed by a pair of parentheses which contain the
parameters, if needed.
Q
10
. How is the main function normally invoked?
This is done automatically by the operating system when the program is executed.
Q
11
. What is the use of return statement?
It specifies the value to be returned by the function. It also terminates the execution
of the function.
Q
12
. What does the return_type_specifier of a function identify?
The return_ type_ specifier identifies the type of value, which will be sent back to the
calling function after the function has performed its task.
Q
13
. Why is the return type void used?
The data type void is used if the function does not return any specific value.
Q
14
. What is the value returned by the statement return (5>7)?
The above statement returns 0, because the 5>7 condition is false.
Q
15
. What is the value returned by the statement return?
The return statement returns standard data type(int, char, float double) or user
defined data to the point from where it was called from, in the calling program.
Q
16
. What is an argument?
A variable declared in a function header, which is used to pass information from
the calling function to be processed by the called function is called an argument.
Q
17
. Why are arguments or parameters used in a function?
The argument list identifies the set of information, which are to be passed to the
function from the main program or another subprogram, to be processed within the
current function.
Q
18
. What is an actual parameter?
A variable or expression listed in a call to a function is called as actual argument or
actual parameter.
Q
19
. Define formal parameter.
A variable declared in a function heading is called formal argument or formal
parameter.
Q
20
. Give the syntax of a function call.
A function call has the following syntax.
Syntax : Variable =Function_ name (arg1, arg2);
Q
21
. Give the syntax of the return statement.
The syntax of the return statement is as follows.
return (expression)
The expression is the value to be returned by the function after processing.
Q
22
. Why is the return statement required in a function body?
To return any value after processing from the function to the calling function.
Q
23
. How many expressions can be included in the return statement?
Only one expression can be included in the return statement.
Q
24
. Why are formal arguments also called as dummy arguments?
This is because formal parameters simply collect the information passed onto them
and not do any passing of information from their part.
Q
25
. What are local variables?
Variables declared within a block and not accessible outside of that block are called
local variables.
Q
26
. What are global variables?
Variables declared outside of all the functions in a program are called global
variables.
Q
27
. What is a function prototype?
A function prototype is a declaration of the function that tells the program about
the type of the value returned by the function and the number and type of
arguments.
Q
28
. Give the syntax of a function prototype.
Syntax of a function prototype is as follows:
return_type function_name(parameter list);
Q
29
. Explain one reason when a function prototype is not necessary.
Function prototype is not necessary when the body of the function appears before
the function is called.
Q
30
. Define the term recursion.
Recursion is a technique whereby a function calls itself directly or indirectly.
Q
31
. Which functions are called as recursive functions?
Functions which are capable of doing the processing by repeatedly calling
themselves and have a particular condition where this self-calling can be stopped.
Q
32
. Explain the term nesting of functions.
Nesting of functions is term used to refer to a function call defined within another
function.
Q
33
. How do we pass an entire array to a function?
We pass an entire array to a function by having the array name as an actual
argument which is also known as call by reference
Q
34
. Define storage class.
A class of variables provides information about the scope of the variable and how
long a variable retains its value.
Q
35
. What are the different types of storage classes?
The different storage classes in C are
1. Automatic storage class 2. Register storage class 3.
Static storage class 4. External storage class
Q
36
. What is automatic storage class?
A variable for which memory is allocated and deallocated when control enters and
exits the block in which it is declared is called as automatic storage class.
Q
37
. What is the use of the keyword auto?
The keyword auto specifies that the corresponding variable declared will have an
automatic storage class.
Q
38
. What does the external storage class indicate?
A variable which is both alive and active throughout the entire program is called an
external storage class.
Q
39
. What is the use of the keyword extern?
The keyword extern specifies that the corresponding variable belongs to extern
storage class and is a global variable.
Q
40
. Why is the static storage class used?
A variable for which memory remains allocated throughout the execution of the
entire program is called a static storage class.
Q
41
. What are register variables?
A variable for which memory is allocated in one of the central processing unit
registers.
Q
42
. Where are register variables created?
Register variables are created and stored inside CPU registers.
Q
43
. Is Register variable does not have address?
Yes.

Q
1
. Give the differences between library functions and user-defined functions.
Library functions are precompiled and are their binary code is available to the
program to be included whenever they are called inside the program. On the other
hand user defined functions are written by the user and have to be compiled every
time the program executes.
Q
2
. What is the need for us to use functions?
With the use of functions, we can modularize a program and make the program well
structured. We can allocate individual tasks to separate functions in the program
so that the division of labour and designing becomes easy. Also we can avoid the
repetition of the function code if it has to be executed in several places in the same
program.
Q
3
. Is main a function? How does it differ from other functions?
Yes. main( ) function is compulsory in any C program and data can be passed to
the program through the command line itself.
Q
4
. Give the structure of a function.

A function contains two parts:
ii. Function body

return_type Function name(argument list) function header
{
function body;
}
Q
5
. Why are arguments or parameters used in a function?
A function sometimes needs certain extra information from the calling program to
be used in the processing to be done by it. This is actually being passed and
collected in a set of parameters of the function. Arguments or parameters are used
to establish the link between calling function and called function.
Q
6
. Explain the parameter passing process in a function call.
When a call of the function is made by mentioning its name in the calling portion,
then the values to the actual parameters is supplied along with it. These values, in
turn are collected by the corresponding formal parameters when the control passes
to the function and the function uses these values in its processing as per the
instructions contained in it.
Q
7
. What is a function call? What is the syntax of a function call?
The function call is the statement which is used to “call” or make the function
execute. When the function call statement is encountered the control of execution
jumps to the called function and the function executes. The syntax of the function
call includes the following

variable = name(actual parameter list);

Q
8
. What is the difference between actual arguments and formal arguments?
Actual arguments are present in the calling part of the function. They pass the
information from the calling side to the function required for processing. Formal
arguments are present within the function header and they are used to collect the
information from the actual arguments into the function for processing.
Q
9
. What is the difference 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 variables are declared outside the function definitions, can be referred to
from any function, and remain in existance for the entire execution of the program.
Q
10
. What is a function prototype? When is a function prototype necessary?
A function prototype is information to the compiler about the function, informing it
about the name, parameters‟ type and number and return type specification. A
prototype is necessary when the function definition has to be clearly conveyed to
the compiler.
Q
11
. Consider the function body
int cat (int x, int y)
{
return ((x>y) ?x:y);
}

What is the output for the function call z=cat(7,5);
Statement (7>5) is true so the ternary operator returns x value that is 7.
Q
12
. How are functions classified?
Functions in C are of four types.
1. Functions with return values and arguments
2. Functions without arguments and return values
3. Functions with return values but no arguments
4. Functions with arguments but no return value.

Q
13
. Consider the function body
int dog (int x, int y)
{
return ((x>y) ?x-y:y-x);
}
Write the above program segment using if statement.
if (x>y)
return(x-y);
else
return(y-x);
Q
14
. Give the general syntax of functions with no arguments and no return values.
main( ) Function name( )
{ {
..... statement1;
Function name( ); ……………...
..... statementn;
} }
Q
15
. Give the general syntax of functions with arguments and no return values.
main( ) Function Function name(argument list)
{ {
.... statement1;
Function name(argument list); ……………...
... statementn;
} }
Q
16
. Give the general syntax of functions with arguments and with return values.
main( ) return_type Function name ( list )
{ {
..... statement1;
varibale=Function name( list ); ……………...
..... return expression;
} }
Q
17
. Give the general syntax of a recursive function.
return_type Function name(argument list)
{
statement1;
.................
Function name (argument list); // recursive call.
}
Q
18
. What are the rules regarding the relationship between the actual parameters that are
passed to a function and its formal parameters?
i. There must be a one to one correspondance between the actual and
formal parameters.
ii. Corresponding parameters must be of the same type.
Q
19
. What are storage classes? What are the different types?
A class of variables provides information about the scope of the variable and how
long a variable retains its value. They are of four types.
1. Automatic storage class
2. Register storage class
3. Static storage class
4. Extern storage class
Q
20
. Explain static storage class.
The static variables come into existance when the program is executed and continue to exist until
the entire program terminates. The static variables defined within the function will
retain their last values. A static variable is initialized only once, when the program
is compiled. It is never initialized again and again.
Q
21
. Explain register storage class.
The register storage class can be specified only for local variables. A computer
contains a small number of registers, or individual storage units. They are similar
to memory except that they are part of the computer processor itself, so operations
on registers are faster than those involving memory.
Q
22
. Differentiate between automatic and external variables.
A variable declared as automatic has
i. Local scope can be accessed only within the block or function where
it is declared.
ii. Lifetime only as long as that of the containing function.
A variable declared as external has
i. Global scope can be accessed from any part of the program.
ii. Lifetime as long as the entire program.

PART C FIVE marks questions Long Answer Questions

2. Explain the concepts of function body, function call and function prototype
with a suitable example.
3. What are the advantages of functions?
4. Show the use of functions without arguments and without return values
with a suitable example.
5. Explain the working of functions with no arguments and no return values.
6. Show the use of functions with arguments and without return values with a
suitable example.
7. Explain the working of functions with arguments and no return values.
8. Show the use of functions with arguments and with return values with a
suitable example.
9. Explain the working of functions with arguments and with return values.
10. What is automatic storage class? Explain with an example.
11. What is external storage class? Explain with an example.
12. Write programs using functions to:
b. Largest of three numbers.
c. Swap the values of two variables using a temporary variable.
d. Swap the values of two variables without using a temporary variable.
e. Output the rightmost digit of a number.
f. Add, subtract and multiply two complex numbers.
g. Find the length of a string.
h. Copy the contents of one string to another.
i. Find the frequency of occurrence of a character in a string.
j. Find the GCD and LCM of two numbers.
k. Find whether a given number is a prime number.
l. Generate prime numbers in a range.
m. Reverse a number.
n. Sum of all odd numbers from 1 to N.
o. Sum of the digits of a given number.
p. Count the number of vowels in a string.
q. Convert a binary number to its equivalent decimal value.
r. Convert a decimal number to its equivalent binary value.
s. Find whether a given number is an Armstrong number
( Example 153 = 13 + 53 + 33 =153 )
t. Generate N numbers of the fibonacci series.
13. Write programs using recursion to :
a. Find the sum of all numbers from 1 to N.
b. Find the factorial of a number.
c. Find x y .
d. Generate the fibonacci series.
e. Find the GCD of two numbers.
f. Find the length of a string.
14. Write programs passing arrays to functions to :
a. Input and output a single dimension array.
b. Find the maximum and minimum in the array.
c. Sort a list of numbers in ascending order.
d. Sort a list of names in alphabetic order.
e. Find the sum of two compatible matrices.
f. Find the product of two compatible matrices.
g. Find the trace of a matrix.
h. Find the norm of a matrix.
i. Find whether a given string is a palindrome.
j. Transpose a matrix.
k. Replace a certain number of characters in a string.

PART D TEN marks questions Very Long Answer Questions

1. Give the general syntax of a function definition and explain its various parts
with suitable examples.
2. Explain the concepts
i. Function definition
ii. Function call
iii. return statement
iv. function prototype
3. Explain :
i. formal and actual arguments
ii. global and local variables
4. Explain the working of functions with no arguments and no return values
with a suitable example.
5. Explain the working of functions with arguments and no return values with a
suitable example.
6. Explain the working of functions with arguments and with return values with a
suitable example.
7. Explain nesting of functions with a suitable example.
8. Explain array of function with a suitable example.
9. Explain the use of various storage classes with suitable examples.
10. Give programming examples to show the use of various storage classes.

CHPATER 14 STRUTURES

Q
1
. What is a structure?
A structure is a heterogeneous data element which can store data elements of
different data types, with the entire structure being given and referenced by a single
name.
Q
2
. Give one difference between an array and a structure.
An array is a homogeneous data element which can store data elements of same
type but a structure is a heterogeneous data element which can store data elements
of different data types.
Q
3
. Does the definition of a structure create memory space for the structure?
The definition of a structure does not actually create memory space for the
variables.
Q
4
. Create a structure definition to store the data of a student.
struct student
{
int regno;
char name[25];
char class[5];
float fees;
int age;
};
Q
5
. Create a structure definition that contains the information of a textbook.
struct textbook
{
char title[25];
char author1[25];
char author2[25];
char publisher[25];
int yearofpublication;
float price;
};
Q
6
. Why is the keyword struct used?
To signify that the element getting declared is a structure.
Q
7
. What are the limitations of a structured declaration?
An individual member in a structure cannot be associated with a storage class.
Also, initilalization of members within the declaration is prohibited.
Q
8
. How are individual elements of a structure accessed?
Using the dot operator which is also known as membership operator.
For example :
structname.fieldname
std.name
where std is a structure variable and name is a structure member.
Q
9
. Why is the dot operator used in a structure?
To access the members of the structure.
Q
10
. Write a structure declaration to store the data of 100 students in a student database.
struct student
{
int regno;
char name[25];
char class[5];
float fees;
int age;
};
struct student s[100];
Q
11
. How do we initialize a structure?
Consider the student structure. Following structure declaration will initialize a
structure.
struct student s1 = {1234,“DRUVA”, “PCMC”,13456.00, 17};
Q
12
. What is a nested structure?
Structure within another structure is called as nested structure.
Q
13
. 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 type.
Q
14
. What is meant by an array of structures?
It is an array in which each element is a structure.
Q
15
. Why an array of structure is used?
We use array of structures to store many elements of structures which in turn
contain many heterogeneous elements.
Q
16
. What is a union?
A union is a user defined data type which can store data elements of different data
types. However, the members that compose a union all share the same storage area
within the computer‟s memory.
Q
17
. Give one difference between a structure and a union.
The members that compose a union all share the same storage area within the
computer‟s memory whereas each member within a structure is assigned its own
unique storage area.
Q
18
. When should we use a union?
Unions are useful for applications involving multiple members, where values need
not be assigned to all of the members at any one time.
Q
19
. Is it possible for us to have an array of structure?
Yes it is possible for us to have an array of structure
Q
20
. Can a structure have elements of the same type?
Yes a structure can have elements of the same type
Q
21
. What is the main difference between structures and unions?
The members of a structure occupy separate areas in memory while members
of a union occupy the same area in memroy.

Q
1
. When is it necessary for us to use a structure data type?
When we have a group of different data types to be stored and referenced as a
single element we use structures. For example, to store the data of a student, we
define structure as follows:
struct student
{
int regno;
char name[25];
char class[5];
float fees;
int age;
};
Q
2
. What are the steps to be followed in creating a structure variable?
The process of defining a structure includes giving the structure a name and telling
the compiler the name and the data type of each piece of data that is to be
included in the structure. The syntax of a structure definition is given below:
struct structure-name
{
data type member_name_1;
data type member_name_2;
..........................
data type member_name_n;
} ;
Q
3
. What are the advantages of structures?
Each variable declared and used in a program can represent one piece of
information. If the number of information increases we may have to use an array.
However an array can handle data of only similar types. But when we are dealing
with dissimilar elements the problem increases. For example if we have to store the
data of an item, we may like to store the name of the item (a string) and its price (a
float). This information about the item has to be stored as one single unit and
accessed as one single unit. In such cases we use structures.
Q
4
. What is a structure tag and what is its purpose?
A structure tag is a name associated with a structure template. This makes it
possible later to declare other variables of the same structure type without having
to rewrite the the template itself.
Q
5
. Why is it necessary for us to first define a structure and then declare a structure?
The process of defining a structure is equivalent to defining your own data type.
The process of defining includes giving the structure a name and telling the
compiler the name and the data type of each piece of data that is to be included in
the structure. In essence we have to first define what is to be contained in the
structure and then declare a variable according to that definition.
Q
6
. How is a structure defined? Give an example.
The syntax of a structure definition is given below:

struct structure-name
{
data type member_name_1;
data type member_name_2;
..........................
data type member_name_n;
} ;

Structure definition that contains the information of a textbook is given below:

struct textbook
{
char title[25];
char author1[25];
char author2[25];
char author3[25];
char publisher[25];
int yearofpublication;
float price;
};
Q
7
. How is a structure declared? Explain with a suitable example.
The keyword struct tells the compiler that, we are referring to a structure type, and
then the structure-name identifies the template that the variable will follow.
Following the structure-name is the name of the variable that we will use in the
program. For example, we can declare the structure variables oldstudent and
newstudent that represent the structure student as follows:
Example:
struct student oldstudent, newstudent;
Thus, oldstudent and newstudent are variables of type student.
Q
8
. What is the difference between a structure definition and a structure declaration?
The process of defining a structure is equivalent to defining your own data type.
struct student
{
int regno;
char name[25];
char class[5];
float fees;
int age;
};
Above structure definition declares a template for the structure and does not
actually allocate memory to the structure variable. But the following structure
declaration allocates memory to it
struct student oldstudent;
Q
9
. Declare a data structure to hold the data of an individual student in a class.
struct student
{
int regno;
char name[25];
char class[5];
float fees;
int age;
};
struct student s;
Q
10
. Declare a data structure to hold the data of all the students in a class.
struct student
{
int regno;
char name[25];
char class[5];
float fees;
int age;
};
struct student s[100];
Q
11
. How can an element of a structure accessed? Explain with a suitable example.
Element of a structure can be accessed by using the dot notation as follows.
Consider the following structure declaration
struct student s1;
Then the accessing will be as follows assuming that the structure contains a name
and an age field.
scanf(“%d”,&S1.age);
scanf(“%s”,s1.name);
Q
12
. How do we initialize the elements of a structure?
We initialize the elements of a structure as follows:

struct student s1 = {
1234,
“Ananth”
“PCMC”
18
};
Q
13
. List out the various operations possible on structures.
i. Accessing of the elements,
ii. storing of the elements and
iii. initialization of the elements
Q
14
. What do we mean by nesting of structures? Explain with a suitable example.
A structure may be defined as a member of another structure. Such structure
where one structure is embedded within another structure is called as a nested
structure. In such situations, the declaration of the embedded structure must
appear before the declaration of the outer structure.

Example : struct date
{
int day;
int month;
int year;
};
struct student
{
int reg_no;
char name[20];
char class[10];
float fees;
struct date dob;
struct date doa;
} oldstudent, newstudent;
Q
15
. What is a union? How is it defined and declared?
A union is a user defined data type which can store data elements of different data
types. However, the members that compose a union all share the same storage area
within the computer‟s memory.

union union-name
{
data type member_name_1;
data type member_name_2;
..........................
data type member_name_n;
};

Example : union item
{
int m;
float p;
char c;
} code;
Q
16
. How is it possible for us to redefine data types using typedef?
It is possible for us to redefine data types in C with the help of typedef i.e., the
typedef feature allows users to define new data types that are equivalent to existing
data types. Once a user-defined data type has been established, then new variables,
arrays and structure can be declared in terms of this new data type.In general, a
new data type is defined as

typedef type new-type;
Example: A simple declaration to illustrate the use of typedef.

typedef int number;

PART C FIVE marks questions Long Answer Questions

1. Write a program to create a structure to hold the data of a point, input data for two
points and find the distance between them.
2. Write a program to create a structure to hold the data of a complex number, input
data for two complex numbers and perform the operation depending on the
operator entered.
3. Write a program to create a structure to hold the data of an employee, input data
for 20 employees and arrange the data in the alphabetic order of their names.
4. Write a program to create a structure to hold the data of a customer, input data for
10 customers and output the data of a required customer.
5. Write a program for matching the names of countries with their corresponding
capitals using structures.
6. Explain the use of arrays within a structure with a programming example.
7. Write a program that creates a structure for a product, which includes product
number, product name and cost input and output data for 10 products.
8. The local police station wants to store the data of all the residents of the area.
Identify the structure declaration to store the data and perform the input and
output operation.
9. Compare the use of structures and unions with a suitable programming example.
10. Write a program to define the variables using typedef and to display the contents of
the variables.