Browse papers
A

Section A: Long Answer Questions

Attempt all / any as specified.

4 questions
1long12 marks

(a) Explain the basic structure of a C program with the help of a suitable example, clearly identifying the preprocessor directives, the main() function, declaration section and the executable statements. (6)

(b) Differentiate between the following pairs of data types in C, stating the typical size and range of each on a 32-bit system: (i) int vs unsigned int and (ii) float vs double. Explain what is meant by type conversion and distinguish between implicit and explicit (type-casting) conversion with one example each. (6)

program-structuredata-typesoperators
2long14 marks

(a) What is recursion? Differentiate between recursion and iteration in terms of memory usage and execution speed. (4)

(b) Write a C program using a recursive function to compute the factorial of a non-negative integer n entered by the user. Show how the recursive calls are placed on and removed from the stack for the input n = 4. (6)

(c) Explain call by value and call by reference with a C example of a swap() function for each, and state which one actually exchanges the values of the caller's variables and why. (4)

functionsrecursioncontrol-flow
3long14 marks

(a) What is a pointer? Explain the & (address-of) and * (dereference) operators with a short program that prints the address and value of a variable using a pointer. (5)

(b) Explain the relationship between arrays and pointers in C. Given the declaration int a[5];, show how a[i] can be accessed using pointer notation. (4)

(c) Describe the use of the functions malloc(), calloc(), realloc() and free() for dynamic memory management. Write a C program that dynamically allocates memory for n integers, reads them, and prints their sum. (5)

pointersdynamic-memoryarrays
4long10 marks

(a) Define a structure Student containing the members roll (integer), name (character array) and marks (float). Write a C program that reads the records of n students and writes them to a file named students.dat, then reads the records back from the file and displays them. (7)

(b) Differentiate between a structure and a union in C with respect to memory allocation, using a suitable example. (3)

structuresunionsfile-handling
B

Section B: Short Answer Questions

Attempt all / any as specified.

8 questions
5short6 marks

Differentiate between while and do-while loops. Write a C program using a loop to check whether a given integer is a prime number.

control-flowloops
6short6 marks

Evaluate the following C expressions, given int a = 5, b = 2, c; and state the value of the result and of any modified variable in each case:

(a) c = a++ + ++b;

(b) c = a % b + a / b;

(c) c = (a > b) ? a : b;

Also explain the difference between the = and == operators.

operatorsexpressions
7short6 marks

Write a C program that reads a string from the user and counts the number of vowels, consonants and spaces in it without using any built-in string library function.

arraysstrings
8short6 marks

Write a C program to find the largest and the second largest element in a one-dimensional array of n integers entered by the user.

arrays
9short6 marks

Differentiate between the break and continue statements with a suitable example of each. Write a C program using nested loops to print the following pattern:

1
1 2
1 2 3
1 2 3 4
control-flowloops
10short6 marks

Explain how a two-dimensional array is stored in memory in C (row-major order). Write a C program to read a 3 x 3 matrix and find the sum of its diagonal elements.

stringsarrays
11short4 marks

List the different file opening modes in C (r, w, a, r+, w+, a+) and explain the purpose of each. State the difference between a text file and a binary file.

file-handling
12short6 marks

Write short notes on any THREE of the following:

(a) Storage classes in C (auto, register, static, extern)

(b) The C preprocessor and #define macros

(c) Difference between getchar()/putchar() and scanf()/printf()

(d) Enumerated data type (enum)

preprocessorprogram-structurefunctions