Browse papers
A

Section A: Long Answer Questions

Attempt all / any as specified.

4 questions
1long12 marks

(a) Describe the basic structure of a C program with the help of a suitable diagram, clearly explaining the role of preprocessor directives, the main() function, declarations, and statements. [6]

(b) What are the fundamental (primitive) data types available in C? Write a program that reads the radius of a circle from the user and prints its area and circumference, using an appropriate symbolic constant for the value of π. [6]

program-structuredata-typescontrol-statements
2long12 marks

(a) What is recursion? Differentiate between a recursive function and an iterative function with respect to memory usage and execution. [4]

(b) Write a recursive C function to compute the factorial of a non-negative integer n, and trace the sequence of recursive calls and returns for n = 4. [4]

(c) Explain the difference between call by value and call by reference with a program that swaps the values of two variables. [4]

functionsrecursionarrays
3long12 marks

(a) What is a pointer? Explain the relationship between arrays and pointers in C, and show how the expression *(arr + i) is equivalent to arr[i]. [6]

(b) Write a C program that uses a pointer to traverse a character array and counts the number of vowels, consonants, and digits in a string entered by the user. [6]

pointersarraysstrings
4long12 marks

(a) Distinguish between a structure and a union in C with respect to memory allocation, giving a suitable example of each. [4]

(b) Define a structure Student containing fields for roll number, name, and marks in three subjects. Write a program that reads records for n students, computes the total and percentage for each, and writes all records to a text file named students.txt. [8]

structuresunionsfile-handling
B

Section B: Short Answer Questions

Attempt all / any as specified.

8 questions
5short6 marks

(a) Differentiate between the increment operators in the expressions x = i++ and x = ++i. [2]

(b) Evaluate the following expression step by step, assuming int a = 5, b = 2, c; and state the final value of c:

c = a + b * 4 / 2 - a % b;

[4]

operatorsexpressions
6short6 marks

Write a C program using a switch statement that reads a single arithmetic operator (+, -, *, /) and two operands from the user, performs the corresponding operation, and prints the result. Handle the case of division by zero appropriately.

control-statements
7short6 marks

Write a C program that reads n integers into a one-dimensional array and finds the largest and smallest elements without using any built-in library functions.

arrayscontrol-statements
8short6 marks

Write a C program to check whether a string entered by the user is a palindrome or not (for example, madam is a palindrome). You may use standard string library functions where appropriate.

stringsarrays
9short6 marks

(a) What is a dangling pointer? How does it arise? [2]

(b) Explain the use of the functions malloc() and free() for dynamic memory allocation, and write a code fragment that dynamically allocates an array of n integers. [4]

pointersfunctions
10short6 marks

(a) List the different file opening modes (r, w, a, etc.) available in C and state the purpose of each. [3]

(b) Write a C program that opens an existing text file in read mode and counts the total number of characters and lines in it. [3]

file-handling
11short6 marks

(a) Differentiate between #define and const for defining constants in C. [2]

(b) What is type conversion? Distinguish between implicit type conversion and explicit type casting with an example of each. [4]

data-typesoperators
12short8 marks

(a) Differentiate between break and continue statements with a short example showing the effect of each inside a loop. [4]

(b) Write a user-defined function isPrime(int n) that returns 1 if n is prime and 0 otherwise, and use it in main() to print all prime numbers between 1 and 50. [4]

control-statementsfunctions