Browse papers
A

Section A: Long Answer Questions

Attempt all / any as specified.

4 questions
1long12 marks

(a) With the help of a neat diagram, explain the basic structure of a C program, clearly describing the role of the preprocessor directives, the main() function, declaration section and the executable statements. (6)

(b) Distinguish between int, float, double and char data types in C in terms of their typical size (in bytes) and range. Write a C program that reads a Celsius temperature from the user and prints the equivalent Fahrenheit temperature, using appropriate data types and format specifiers. (6)

program-structuredata-typesoperators
2long14 marks

(a) Differentiate between the while, do...while and for looping constructs in C with their general syntax and a suitable example of each. State clearly the situation in which a do...while loop is preferred. (7)

(b) Write a C program using a switch...case statement that behaves as a simple calculator. The program should read two operands and an operator (+, -, *, /) from the user and display the result. Handle the division-by-zero case appropriately. (7)

control-flowloops
3long14 marks

(a) What is recursion? Explain the concept of a recursive function with the help of the factorial example, and discuss how it differs from an iterative solution in terms of memory and the function call stack. (6)

(b) Write a C program that uses a user-defined function to search for a given element in a one-dimensional integer array using the linear search technique. The function should return the index of the element if found, or -1 otherwise. (8)

functionsrecursionarrays
4long12 marks

(a) What is a pointer? Explain the meaning of the & (address-of) and * (dereference) operators with a suitable example showing how a pointer is declared, initialized and used to modify the value of a variable. (6)

(b) Explain the difference between malloc() and calloc(). Write a C program that dynamically allocates memory for n integers (where n is entered by the user), reads them, prints their sum, and finally frees the allocated memory. (6)

pointersdynamic-memory
B

Section B: Short Answer Questions

Attempt all / any as specified.

7 questions
5short6 marks

Explain the difference between the logical operators (&&, ||, !) and the bitwise operators (&, |, ^) in C. Evaluate the expression a = 5 + 3 * 2 - 8 / 4 step by step using operator precedence and show the final value of a.

operatorsexpressions
6short6 marks

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

arraysstrings
7short6 marks

Differentiate between call by value and call by reference in C with a suitable example. Illustrate by writing a function swap() that successfully exchanges the values of two variables passed from main().

functionsarrays
8short6 marks

(a) How does a structure differ from a union in terms of memory allocation? (2)

(b) Define a structure Student having members roll (integer), name (string) and marks (float). Write a C program to read details of 3 students into an array of structures and display the name of the student with the highest marks. (4)

structuresunions
9short6 marks

Explain the different modes (r, w, a) used to open a file in C. Write a C program that opens a text file named data.txt, writes the numbers from 1 to 10 into it, and then closes the file, checking for any error during file opening.

file-handling
10short6 marks

Write a C program to check whether a given positive integer entered by the user is a prime number or not, and display an appropriate message.

control-flowloops
11short6 marks

Write short notes on any TWO of the following: (a) Storage classes in C (auto, static, register, extern); (b) #define macros versus constant variables; (c) Type conversion and type casting in C.

data-typesprogram-structure