Browse papers
A

Section A: Long Answer Questions

Attempt any TWO questions.

3 questions·10 marks each
1long10 marks

Explain different types of decision-making (branching) statements in C with syntax and examples. Differentiate if-else with switch statement.

Decision-Making (Branching) Statements in C

Decision-making statements let a program choose among different paths of execution based on the result of a condition (an expression that evaluates to true/non-zero or false/zero).

1. Simple if statement

Executes a block only when the condition is true.

if (condition) {
    // statements executed when condition is true
}

Example:

if (marks >= 40)
    printf("Passed\n");

2. if-else statement

Provides an alternative block when the condition is false.

if (condition) {
    // true block
} else {
    // false block
}

Example:

if (n % 2 == 0)
    printf("Even\n");
else
    printf("Odd\n");

3. else-if ladder (nested if-else)

Used to test a series of mutually exclusive conditions.

if (marks >= 80)      grade = 'A';
else if (marks >= 60) grade = 'B';
else if (marks >= 40) grade = 'C';
else                  grade = 'F';

4. switch statement

Selects one of many code blocks by matching an integer/character expression against constant case labels.

switch (expression) {
    case const1: statements; break;
    case const2: statements; break;
    default:     statements;
}

Example:

switch (day) {
    case 1: printf("Sunday\n");  break;
    case 2: printf("Monday\n");  break;
    default: printf("Other\n");
}

Difference between if-else and switch

Basisif-elseswitch
Condition typeAny relational/logical expression (ranges allowed)Only equality against integer/char constants
EvaluationEach condition evaluated in sequenceSingle expression evaluated once, jumps to matching case
Data typesint, float, char, etc.int and char only
breakNot requiredRequired to avoid fall-through
Default actionelsedefault
SpeedSlower for many conditionsFaster (jump table) for many fixed values

Conclusion: Use if-else for range or complex logical conditions; use switch when one variable is compared with many constant values.

control-flow
2long10 marks

What is a function? Explain function declaration, definition and call. Differentiate call by value and call by reference with examples.

Function in C

A function is a self-contained, named block of code that performs a specific task. It can be called (invoked) any number of times, supports modular programming, reduces code duplication, and improves readability and reusability.

A function works through three parts:

1. Function Declaration (Prototype)

Tells the compiler the function's name, return type and parameter types before it is used. It ends with a semicolon.

int add(int a, int b);   // declaration / prototype

2. Function Definition

Contains the actual body (logic) of the function.

int add(int a, int b) {   // definition
    return a + b;
}

3. Function Call

Invokes the function and (optionally) passes arguments and receives a return value.

int sum = add(5, 3);   // call -> sum = 8

Call by Value vs Call by Reference

Call by Value: A copy of the actual argument is passed to the function. Changes made to the parameters inside the function do not affect the original variables.

void swap(int x, int y) {   // call by value
    int t = x; x = y; y = t;
}
int a = 2, b = 5;
swap(a, b);   // a and b remain 2 and 5

Call by Reference: The address of the actual argument is passed (using pointers). The function works on the original memory, so changes are reflected in the caller.

void swap(int *x, int *y) {  // call by reference
    int t = *x; *x = *y; *y = t;
}
int a = 2, b = 5;
swap(&a, &b);  // a and b become 5 and 2
BasisCall by ValueCall by Reference
What is passedCopy of valueAddress of variable
Effect on originalNo changeOriginal is modified
MemoryExtra copy createdNo copy, uses pointer
SafetySaferOriginal can be altered
functions
3long10 marks

Write a program to read a matrix of order m x n and find the transpose of the matrix.

Program: Transpose of an m x n Matrix

The transpose of a matrix is obtained by interchanging its rows and columns: element A[i][j]A[i][j] of the original becomes element T[j][i]T[j][i] of the transpose. If AA is of order m×nm \times n, its transpose TT is of order n×mn \times m.

#include <stdio.h>

int main() {
    int a[10][10], t[10][10];
    int m, n, i, j;

    printf("Enter rows (m) and columns (n): ");
    scanf("%d %d", &m, &n);

    printf("Enter %d x %d matrix elements:\n", m, n);
    for (i = 0; i < m; i++)
        for (j = 0; j < n; j++)
            scanf("%d", &a[i][j]);

    // Compute transpose: t[j][i] = a[i][j]
    for (i = 0; i < m; i++)
        for (j = 0; j < n; j++)
            t[j][i] = a[i][j];

    printf("Transpose (%d x %d):\n", n, m);
    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++)
            printf("%d\t", t[i][j]);
        printf("\n");
    }
    return 0;
}

Sample Run

Enter rows (m) and columns (n): 2 3
Enter 2 x 3 matrix elements:
1 2 3
4 5 6
Transpose (3 x 2):
1   4
2   5
3   6

Logic: Read the matrix with nested loops, then store each a[i][j] into t[j][i], swapping the row and column indices to form the transpose.

arrays
B

Section B: Short Answer Questions

Attempt any EIGHT questions.

9 questions·5 marks each
4short5 marks

What are tokens in C? Explain different types of tokens.

Tokens in C

A token is the smallest individual (indivisible) unit of a C program that is meaningful to the compiler. The C compiler breaks the source program into tokens during the lexical-analysis phase. C has six types of tokens:

  1. Keywords — reserved words with predefined meaning that cannot be used as identifiers, e.g. int, if, while, return, for, void (32 keywords in standard C).
  2. Identifiers — user-defined names for variables, functions, arrays, etc. (e.g. sum, count, main). They must begin with a letter or underscore and cannot be a keyword.
  3. Constants (Literals) — fixed values that do not change, e.g. integer 10, float 3.14, character 'A', string "Hello".
  4. Strings — a sequence of characters enclosed in double quotes, e.g. "CSIT". (Often grouped with constants.)
  5. Operators — symbols that perform operations, e.g. arithmetic + - * /, relational > <, logical && ||, assignment =.
  6. Special symbols / Punctuators — symbols such as { } [ ] ( ) ; , # used for grouping, separation and preprocessing.

Example: In int sum = a + b;, the tokens are int (keyword), sum, a, b (identifiers), =, + (operators), and ; (special symbol).

tokens
5short5 marks

Explain the use of getchar() and putchar() functions with example.

getchar() and putchar()

Both are character I/O functions declared in <stdio.h>.

getchar()

Reads a single character from the standard input (keyboard) and returns it as an int. Syntax: ch = getchar();

putchar()

Writes a single character to the standard output (screen). Syntax: putchar(ch);

Example

#include <stdio.h>
int main() {
    char ch;
    printf("Enter a character: ");
    ch = getchar();          // read one character
    printf("You entered: ");
    putchar(ch);             // print that character
    putchar('\n');
    return 0;
}

Sample Output

Enter a character: A
You entered: A

getchar() accepts one character from the user and putchar() displays it. They are simple, fast functions for character-by-character input/output.

io-functions
6short5 marks

Write a program to find the factorial of a number using recursion.

Factorial Using Recursion

The factorial of a non-negative integer nn is defined recursively as:

n!={1n=0n×(n1)!n>0n! = \begin{cases} 1 & n = 0 \\ n \times (n-1)! & n > 0 \end{cases}

A recursive function calls itself with a smaller value until it reaches the base case (n=0n = 0 or 11).

#include <stdio.h>

long factorial(int n) {
    if (n <= 1)                 // base case
        return 1;
    return n * factorial(n - 1); // recursive case
}

int main() {
    int n;
    printf("Enter a number: ");
    scanf("%d", &n);
    printf("Factorial of %d = %ld\n", n, factorial(n));
    return 0;
}

Sample Run

Enter a number: 5
Factorial of 5 = 120

Working: factorial(5) = 5 * factorial(4) = 54factorial(3) ... = 54321 = 120. The base case stops the recursion.

recursion
7short5 marks

What is a string? Explain any four built-in string handling functions.

String in C

A string is a one-dimensional array of characters terminated by a null character '\0'. It is used to store text. Example: char name[] = "CSIT"; stores C S I T \0 (5 bytes).

C provides built-in string-handling functions in the header <string.h>. Four important ones are:

  1. strlen(s) — Returns the length of string s (number of characters, excluding '\0'). strlen("hello")5.
  2. strcpy(dest, src) — Copies string src into dest (including '\0'). strcpy(t, "abc"); makes t = "abc".
  3. strcat(dest, src) — Appends (concatenates) src to the end of dest. If s1 = "Good", strcat(s1, "Day")"GoodDay".
  4. strcmp(s1, s2) — Compares two strings lexicographically; returns 0 if equal, a negative value if s1 < s2, and positive if s1 > s2.

Example

#include <stdio.h>
#include <string.h>
int main() {
    char a[20] = "Hello", b[20] = "World";
    printf("Length of a = %lu\n", strlen(a));
    strcat(a, b);              // a = "HelloWorld"
    printf("After concat: %s\n", a);
    printf("Compare: %d\n", strcmp("abc", "abc")); // 0
    return 0;
}
strings
8short5 marks

Differentiate between structure and union with example.

Structure vs Union

A structure (struct) is a user-defined data type that groups related variables of different types under one name; each member gets its own separate memory.

A union groups members of different types under one name, but all members share the same memory location (size = size of the largest member); only one member holds a valid value at a time.

struct S { int i; char c; float f; };  // separate memory for each
union  U { int i; char c; float f; };  // all share one memory block
BasisStructureUnion
Keywordstructunion
MemorySum of all members' sizesSize of the largest member
Member accessAll members usable at onceOnly one member at a time
Value storageEach member keeps its own valueMembers overwrite each other
UseWhen all fields are needed togetherWhen only one field is used at a time (saves memory)

Example

#include <stdio.h>
struct S { int a; char b; };
union  U { int a; char b; };
int main() {
    printf("struct size = %lu\n", sizeof(struct S)); // e.g. 8 (with padding)
    printf("union  size = %lu\n", sizeof(union  U)); // 4 (largest member)
    return 0;
}

In a structure, assigning s.a does not affect s.b; in a union, assigning u.a overwrites u.b because they occupy the same memory.

structures
9short5 marks

Explain the relationship between arrays and pointers.

Relationship Between Arrays and Pointers

In C, arrays and pointers are closely related:

  1. Array name as pointer: The name of an array acts as a constant pointer to its first element. For int a[5];, the expression a is equivalent to &a[0]. So *a gives a[0].

  2. Pointer arithmetic = indexing: Adding to a pointer moves it by element size. Therefore:

a[i](a+i)(p+i)p[i]a[i] \equiv *(a + i) \equiv *(p + i) \equiv p[i]

where p = a;. The compiler internally translates a[i] into *(a + i).

  1. Passing arrays to functions: When an array is passed to a function, only the address of its first element is passed (it "decays" to a pointer); the function receives a pointer, not a copy of the array.

  2. Difference: An array name is a constant address (cannot be reassigned, e.g. a++ is illegal), whereas a pointer is a variable that can be reassigned (p++ is valid).

Example

#include <stdio.h>
int main() {
    int a[3] = {10, 20, 30};
    int *p = a;              // p points to a[0]
    printf("%d %d\n", a[1], *(p + 1)); // both print 20
    printf("%d\n", *(a + 2));          // prints 30 (a[2])
    return 0;
}

Thus arrays can be processed using pointer notation and vice versa, but the array name itself is a fixed (non-modifiable) pointer.

pointers
10short5 marks

Write a program to display the Fibonacci series up to n terms.

Fibonacci Series up to n Terms

In the Fibonacci series each term is the sum of the two preceding terms, starting with 0 and 1:

0, 1, 1, 2, 3, 5, 8, 13, 0,\ 1,\ 1,\ 2,\ 3,\ 5,\ 8,\ 13,\ \dots
#include <stdio.h>

int main() {
    int n, i;
    int t1 = 0, t2 = 1, next;

    printf("Enter number of terms: ");
    scanf("%d", &n);

    printf("Fibonacci series: ");
    for (i = 1; i <= n; i++) {
        printf("%d ", t1);
        next = t1 + t2;   // next term
        t1 = t2;
        t2 = next;
    }
    printf("\n");
    return 0;
}

Sample Run

Enter number of terms: 7
Fibonacci series: 0 1 1 2 3 5 8

Logic: Start with t1 = 0, t2 = 1; in each iteration print t1, compute next = t1 + t2, then shift the window forward (t1 = t2, t2 = next).

loops
11short5 marks

Explain the use of #define and #include preprocessor directives.

#define and #include Preprocessor Directives

Preprocessor directives begin with # and are processed by the preprocessor before actual compilation.

#include

Used to insert (copy) the contents of a header file into the program.

  • #include <stdio.h> — searches the standard system directories (for library headers).
  • #include "myfile.h" — searches the current/user directory first (for user-defined headers). It gives access to library function declarations such as printf, scanf, etc.

#define

Used to define symbolic constants (macros) and macro functions. The preprocessor replaces every occurrence of the macro name with its value/expansion before compilation.

#define PI 3.14159          // object-like macro (symbolic constant)
#define SQUARE(x) ((x)*(x)) // function-like macro

Usage:

#include <stdio.h>
#define PI 3.14159
#define SQUARE(x) ((x)*(x))
int main() {
    printf("Area = %f\n", PI * SQUARE(5)); // PI*25
    return 0;
}

Summary: #include brings external file contents into the program, while #define creates constants/macros that are textually substituted, improving readability and easy maintenance.

preprocessor
12short5 marks

What is dynamic memory allocation? Explain malloc() and calloc().

Dynamic Memory Allocation (DMA)

Dynamic memory allocation is the process of allocating memory at run time (rather than compile time) from the heap. It allows programs to request exactly as much memory as needed and to resize/free it later, which is useful when the data size is unknown in advance. The functions are declared in <stdlib.h>, and freed using free().

malloc() — Memory Allocation

Allocates a single block of the requested size in bytes and returns a void* pointer to it. The allocated memory is uninitialized (contains garbage). Returns NULL on failure.

int *p = (int *) malloc(5 * sizeof(int)); // block for 5 ints

Syntax: ptr = (type*) malloc(size_in_bytes);

calloc() — Contiguous Allocation

Allocates memory for an array of n elements each of given size and initializes all bytes to zero. Returns NULL on failure.

int *p = (int *) calloc(5, sizeof(int)); // 5 ints, all set to 0

Syntax: ptr = (type*) calloc(n, size_of_each);

Difference

Basismalloc()calloc()
ArgumentsOne (total bytes)Two (count, size)
InitializationGarbage (uninitialized)All zeros
SpeedSlightly fasterSlightly slower (zeroing)

Memory obtained from either must be released with free(p); to avoid memory leaks.

memory

Frequently asked questions

Where can I find the BSc CSIT (TU) C Programming (BSc CSIT, CSC115) question paper 2075?
The full BSc CSIT (TU) C Programming (BSc CSIT, CSC115) 2075 (regular) question paper is available free on Kekkei. You can read every question online and attempt the paper under timed exam conditions.
Does the C Programming (BSc CSIT, CSC115) 2075 paper come with solutions?
Yes. Every question on this C Programming (BSc CSIT, CSC115) past paper includes a step-by-step solution, plus instant AI feedback when you attempt it on Kekkei.
How many marks is the BSc CSIT (TU) C Programming (BSc CSIT, CSC115) 2075 paper?
The BSc CSIT (TU) C Programming (BSc CSIT, CSC115) 2075 paper carries 60 full marks and is meant to be completed in 180 minutes, across 12 questions.
Is practising this C Programming (BSc CSIT, CSC115) past paper free?
Yes — reading and attempting this C Programming (BSc CSIT, CSC115) past paper on Kekkei is completely free.