You are on page 1of 5

20USC101

AYYA NADAR JANAKI AMMAL COLLEGE ( AUTONOMOUS), SIVAKASI


TERMINAL EXAMINATIONS, NOVEMBER 2021
UNDERGRADUATE DEGREE COURSES FIRST SEMESTER
PART – III PROGRAMMING IN C
(for those admitted in JUNE 2020 and later)
Scheme of Valuation
Time: 3 Hours Maximum : 60 Marks
Section –A ( 5*2= 10 Marks)
ANSWER ALL QUESTIONS:
1. In C programming language, a block is created using a pair of curly braces. The
beginning of the block is denoted by an open curly brace '{' and the end is denoted by a
closing curly brace '}'. The block collects statements together into a single compound
statement. – 1 mark
Example :

if(i==j)
{
Printf(“matrix \n”);
} - 1 mark

2. The sizeof() operator is a compile-time unary operator and used to compute the size of its
operand. It returns the size of a variable. It can be applied to any data type, float type, pointer
type variables. - 2 marks
3. Variable length arguments is a programming construct that allows programmers to
pass n number of arguments to a function. You can also call variable length argument as var-
args. – 1 mark
Declaration: int maximum(int n1, int n2, int n3, int n4, int n5); // Find maximum between
five numbers - 1 mark
4. int *ptr is the declaration of pointer which stores the address of the integer variable and
int **ptr is the declaration that stores the address of the pointer storing the integer variable.
- 2 marks.
5. A stream is a logical entity that represents a file or device, that can
accept input or output. All input and output functions in standard C, operate on data streams.
Streams can be divided into text, streams and binary streams. - 2 marks
SECTION –B
ANSWER ALL QUESTIONS (5*4= 20 Marks)
6.a. Discussion of any two characteristics of static variables, such as Local static variable,
Global static variables, Variable declaration – 2 marks
Discussion of any two characteristics of register variables. - 2 marks

6.b. There are following types of conditional statements in C.

1. If statement
2. If-Else statement
3. Nested If-else statement
4. If-Else If ladder
5. Switch statement - 2 marks
Explanation of any two conditional statements - 2 marks

7.a. In programming terminology, a bit field is a data structure that allows the programmer to
allocate memory to structures and unions in bits in order to utilize computer memory in an
efficient manner. - 2 marks
Example program - 1 mark
Bit fields can be used to reduce memory consumption when a program requires a number of
integer variables which always will have low values. - 1 mark

7.b. In C programming, you can create an array of arrays known as a multi-dimensional


array. For example,
Float x[3][4];
Here, x is a two-dimensional (2d) array. The array can hold 12 elements. You can think the
array as a table with 3 row and each row has 4 column.

- 2 marks
Similarly, you can declare a three-dimensional (3d) array. For example,

float y[2][4][3];
Here, The array y can hold 24 elements.
You can think this example as: Each 2 elements have 4 elements, which makes 8 elements
and each 8 elements can have 3 elements. Hence, the total number of elements is 24.
- 2 marks
8.a. Syntax - 1 mark

Example program with explanation - 3 marks

8.b. File Scope - Scope of an Identifier starts at the beginning of the file and ends at the end
of the file. It refers to only those Identifiers that are declared outside of all functions. The
Identifiers of File scope are visible all over the file Identifiers having file scope are global.
Block Scope - Scope of a Identifier begins at opening of the block / ‘{‘ and ends at the end
of the block / ‘}’. Identifiers with block scope are local to their block.
Function Prototype Scope - Identifiers declared in function prototype are visible within the
prototype.
Function scope - Function scope begins at the opening of the function and ends with the
closing of it. Function scope is applicable to labels only. A label declared is used as a target
to goto statement and both goto and label statement must be in same function.
- (1+1+1+1) = 4marks

9.a. /* Function declaration */


void inputArray(int * arr, int size);
void printArray(int * arr, int size);

/* Sort function declaration */


int sortAscending(int * num1, int * num2);
int sortDescending(int * num1, int * num2); - 1 marks
Program Logic - 2 marks
Sample Input: Input array elements: 10 -1 0 4 2 100 15 20 24 -5
Sample Output: Array in ascending order: -5, -1, 0, 2, 4, 10, 15, 20, 24, 100,
Array in descending order: 100, 24, 20, 15, 10, 4, 2, 0, -1, -5 - 1 mark

9.b. Get string input using gets() function


Char data[100];
gets(data); - 2 marks
Print string using puts() function
Puts(data); - 1 mark
Sample Input & Output - 1 mark
10.a. #ifdef DEBUG
/* Your debugging statements here */
#endif
Tells the CPP to do the following statements if DEBUG is defined. This is useful if you pass
the -DDEBUG flag to gcc. This will define DEBUG, so you can turn debugging on and off on
the fly! - 2 marks
The #undef preprocessor directive is used to undefined macros. 
Syntax:
#undef macro-name - 1 mark
#undef example - 1 mark

10.b.

The ftell() function tells us about the current position in the file (in bytes).

Syntax: pos=ftell(fptr);

We use the rewind() function to return back to the starting point in the file.

Syntax: rewind(fptr);

We use the fseek() function to move the file position to a desired location.

Syntax: fseek(fptr,offset,position); Any two functions (2+2) – 4 marks

SECTION – C
ANSWER ALL QUESTIONS (3*10= 30 Marks)
11.a. List of Looping statements
i)for() ii)while() iii)do-while() - 1 mark
Working principles of for() loop - 3 marks
Working principles of while() loop - 3 marks
Working principles of do-while() loop - 3 marks
11.b. Determination of Structure within the Structure - 4 marks
Example program & Output - 6 marks
12.a. Explanation of passing a structure to function - 2 marks
Syntax - 2 marks
Example program & Output - 6 marks
12.b. malloc() - It is used to dynamically allocate a single large block of memory with the
specified size. – 0.5 mark
Syntax: ptr = (cast-type*) malloc(byte-size) - 1 mark
calloc() - It is used to dynamically allocate the specified number of blocks of memory of the
specified type. - 0.5 mark
Syntax: ptr = (cast-type*)calloc(n, element-size); - 1 mark
free() -  It is used to dynamically de-allocate the memory. – 0.5 mark
Syntax: free(ptr); - 1 mark
realloc() – It is used to dynamically change the memory allocation of a previously allocated
memory.  – 0.5 mark
Syntax: ptr = realloc(ptr, newSize); - 1 mark
Example program -4 marks
13.a. Declarations & Inputs - 2 marks
Program logic – 6.5 marks
Output - 1.5 marks
13.b. Declarations & Inputs - 2 marks
Program logic - 6.5 marks
Output - 1.5 marks

Staff-Incharge Head of the Department

(Mr.P.Manivannan) (Mr.V.VenkateshBabu)

-----------------------------------------------

You might also like