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, clearly explaining the role of preprocessor directives, the main() function, declarations, and statements. (b) What is meant by a token in C? List and briefly explain the different categories of tokens. (c) Differentiate between the storage classes auto, static, extern, and register with respect to their scope, lifetime, and default initial value.

program-structuredata-typesfunctions
2long12 marks

(a) Distinguish between call by value and call by reference with a suitable example for each. (b) Write a C program using a recursive function to compute the factorial of a number entered by the user, and explain how the recursion unwinds for an input of 4. (c) How does passing a one-dimensional array to a function differ from passing an ordinary variable?

functionsrecursionarrays
3long12 marks

(a) What is a pointer? Explain the relationship between arrays and pointers with reference to how the expression a[i] is evaluated by the compiler. (b) Write a C program that reads a string from the user and counts the number of vowels, consonants, and digits in it using pointer notation (do not use array subscripting). (c) Explain the meaning of the declaration int *p[10]; and how it differs from int (*p)[10];.

pointersarraysstrings
4long12 marks

(a) Define a structure named Student containing fields for roll number, name, and marks in three subjects. Write a C program that reads records of n students, computes the total and average marks of each, and writes the records to a file named student.dat. (b) Explain the difference between a structure and a union in terms of memory allocation, giving a suitable diagram. (c) Differentiate between text mode and binary mode of opening a file.

structuresunionsfile-handling
B

Section B: Short Answer Questions

Attempt all / any as specified.

7 questions
5short8 marks

(a) Explain operator precedence and associativity with an example. Evaluate the expression a = 5 + 3 * 2 - 8 / 4 % 3 step by step, showing the value of a. (b) What is the difference between i++ and ++i? Determine the output of the following code:

int i = 5, j;
j = i++ + ++i;
printf("%d %d", i, j);
operatorsexpressions
6short8 marks

(a) Differentiate between the while loop and the do-while loop with a flowchart for each. (b) Write a C program using a switch statement that takes a single character operator (+, -, *, /) and two operands from the user and performs the corresponding arithmetic operation, handling division by zero appropriately.

control-statements
7short8 marks

(a) Write a C program to read a 3x3 matrix and find the transpose of the matrix, displaying both the original and the transposed matrix. (b) Explain any four standard string-handling library functions in C with their syntax and a one-line description of each.

arraysstrings
8short8 marks

(a) Differentiate between printf() and scanf() functions, explaining the meaning of the format specifiers %d, %f, %c, and %s. (b) What will be the output of the following program? Justify your answer.

#include <stdio.h>
int main() {
    int a = 10;
    float b = 3;
    printf("%d\n", a / (int)b);
    printf("%.2f\n", a / b);
    return 0;
}
data-typesprogram-structure
9short8 marks

(a) What is dynamic memory allocation? Explain the use of malloc(), calloc(), and free() with their syntax. (b) Write a C program that dynamically allocates memory for an array of n integers entered by the user, finds the largest element, and frees the allocated memory before exiting.

pointersfunctions
10short8 marks

(a) List and explain the different file opening modes (r, w, a, r+, w+, a+) used with fopen(). (b) Write a C program that opens an existing text file, reads it character by character, copies its contents to another file, and counts the total number of lines in the file.

file-handling
11short6 marks

Write a C program to generate and display the first n terms of the Fibonacci series, where n is entered by the user, using an iterative approach. Briefly explain how the same result could be achieved using recursion.

functionsrecursioncontrol-statements