Browse papers
A

Section A: Long Answer Questions

Attempt any TWO questions.

3 questions·10 marks each
1long10 marks

Explain the various data types available in C with their memory size and range. Why is type conversion needed?

Data Types in C

A data type specifies the kind of value a variable can hold, how much memory it occupies, and the range of values allowed. C data types are broadly classified as:

  • Primary / Basic types: int, char, float, double
  • Derived types: arrays, pointers, functions
  • User-defined types: struct, union, enum, typedef
  • Void type: void (no value)

Basic Types with Size and Range (typical 32/64-bit system)

TypeSize (bytes)Range
char1128-128 to 127127
unsigned char100 to 255255
short int232768-32768 to 3276732767
int42147483648-2147483648 to 21474836472147483647
unsigned int400 to 42949672954294967295
long int4 or 8up to ±9.2×1018\pm 9.2\times10^{18}
float43.4×1038\approx 3.4\times10^{-38} to 3.4×10383.4\times10^{38} (6 digits precision)
double81.7×10308\approx 1.7\times10^{-308} to 1.7×103081.7\times10^{308} (15 digits)
long double10/12/16extended precision

Sizes are implementation-dependent; the exact size on a given machine is obtained with the sizeof operator.

Why Type Conversion is Needed

Type conversion changes a value from one data type to another. It is needed because:

  1. Mixed-type expressions — when operands of different types appear together (e.g. int + float), the compiler must convert them to a common type to evaluate the expression correctly.
  2. Preventing data/precision loss — e.g. dividing two integers gives an integer; converting one to float gives an accurate fractional result.
  3. Assignment compatibility — assigning a value to a variable of a different type requires conversion.
  4. Memory/range matching — to fit values into the correct range and avoid overflow.

There are two kinds:

  • Implicit (automatic) conversion — done by the compiler following type promotion rules: char → int → float → double.
  • Explicit conversion (type casting) — done by the programmer using the cast operator, e.g. float avg = (float)sum / n;
data-types
2long10 marks

What is an array? Explain how a two-dimensional array is declared, initialized and accessed with an example. Write a program for matrix addition.

Array

An array is a collection of elements of the same data type stored in contiguous memory locations and referred to by a common name. Individual elements are accessed using an index that starts from 0.

Two-Dimensional Array

A 2-D array represents data in rows and columns (a matrix/table).

Declaration

data_type array_name[rows][cols];
int a[3][3];   /* 3 rows, 3 columns */

Initialization

int a[2][3] = { {1, 2, 3}, {4, 5, 6} };

Accessing

An element is accessed as a[i][j], where i is the row index and j is the column index (both starting from 0). For example, a[1][2] accesses the element in the 2nd row, 3rd column.

for (i = 0; i < 2; i++)
    for (j = 0; j < 3; j++)
        printf("%d ", a[i][j]);

Program: Matrix Addition

#include <stdio.h>
int main() {
    int a[10][10], b[10][10], c[10][10];
    int m, n, i, j;

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

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

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

    /* Add corresponding elements */
    for (i = 0; i < m; i++)
        for (j = 0; j < n; j++)
            c[i][j] = a[i][j] + b[i][j];

    printf("Sum of matrices:\n");
    for (i = 0; i < m; i++) {
        for (j = 0; j < n; j++)
            printf("%d ", c[i][j]);
        printf("\n");
    }
    return 0;
}

The addition is defined as cij=aij+bijc_{ij} = a_{ij} + b_{ij} for all i,ji, j, which requires both matrices to have the same dimensions.

arrays
3long10 marks

Explain file handling in C. Write a program to read content from one file and copy it into another file.

File Handling in C

File handling allows a program to store data permanently on secondary storage and to read it back later, instead of losing it when the program ends. C accesses files through a pointer of type FILE * defined in <stdio.h>.

Steps

  1. Declare a file pointer: FILE *fp;
  2. Open the file: fp = fopen("name.txt", "mode");
  3. Process (read/write) the file.
  4. Close the file: fclose(fp);

Common File Modes

ModeMeaning
"r"open for reading (file must exist)
"w"open for writing (creates/overwrites)
"a"open for appending
"r+"read and write
"rb","wb"binary read/write

Common File Functions

fopen(), fclose(), fgetc()/fputc(), fgets()/fputs(), fscanf()/fprintf(), fread()/fwrite(), feof(), rewind().

Program: Copy Contents of One File to Another

#include <stdio.h>
#include <stdlib.h>
int main() {
    FILE *src, *dest;
    char ch;

    src = fopen("source.txt", "r");
    if (src == NULL) {
        printf("Cannot open source file.\n");
        exit(1);
    }

    dest = fopen("destination.txt", "w");
    if (dest == NULL) {
        printf("Cannot open destination file.\n");
        fclose(src);
        exit(1);
    }

    /* Read character by character until end of file */
    while ((ch = fgetc(src)) != EOF)
        fputc(ch, dest);

    printf("File copied successfully.\n");

    fclose(src);
    fclose(dest);
    return 0;
}

The loop reads each character from source.txt using fgetc() and writes it to destination.txt using fputc() until EOF is reached.

files
B

Section B: Short Answer Questions

Attempt any EIGHT questions.

9 questions·5 marks each
4short5 marks

Differentiate between compiler and interpreter.

Compiler vs Interpreter

Both are translators that convert high-level source code into machine code, but they differ in approach:

CompilerInterpreter
Translates the entire program at once into machine code (object/executable file).Translates and executes the program line by line.
Execution is faster after compilation.Execution is slower (translation each run).
Generates a separate executable / object file.Does not produce a separate object file.
Reports all errors together after scanning the whole program.Reports errors one at a time and stops at the first error.
Needs more memory at compile time.Generally needs less memory.
Example languages: C, C++.Example: Python, BASIC.

In short, a compiler trades slower (one-time) translation for faster repeated execution, while an interpreter gives immediate execution but slower runtime.

fundamentals
5short5 marks

Explain the use of the goto statement with an example.

The goto Statement

The goto statement is an unconditional jump that transfers control directly to a labeled statement anywhere within the same function.

Syntax

goto label;
...
label:
    statement;

A label is an identifier followed by a colon (:).

Example: Print numbers 1 to 5 using goto

#include <stdio.h>
int main() {
    int i = 1;
start:                 /* label */
    printf("%d ", i);
    i++;
    if (i <= 5)
        goto start;    /* jump back to label */
    return 0;
}

Output: 1 2 3 4 5

Use and Caution

goto can be used to break out of deeply nested loops or jump to a common error-handling section. However, its use is discouraged because it makes programs hard to read, debug, and maintain ("spaghetti code"). Structured statements like break, continue, loops, and functions are preferred alternatives.

control-flow
6short5 marks

What is a nested loop? Write a program to print a pyramid pattern of stars.

Nested Loop

A nested loop is a loop placed inside the body of another loop. For each single iteration of the outer loop, the inner loop executes completely. Nested loops are commonly used to process 2-D structures (matrices) and to print patterns. If the outer loop runs mm times and the inner nn times, the inner body executes m×nm \times n times.

Program: Pyramid Pattern of Stars

#include <stdio.h>
int main() {
    int rows, i, j;
    printf("Enter number of rows: ");
    scanf("%d", &rows);

    for (i = 1; i <= rows; i++) {
        /* print leading spaces */
        for (j = 1; j <= rows - i; j++)
            printf(" ");
        /* print stars */
        for (j = 1; j <= 2 * i - 1; j++)
            printf("*");
        printf("\n");
    }
    return 0;
}

Sample output (rows = 4):

   *
  ***
 *****
*******

The outer loop controls the rows; the first inner loop prints rows - i spaces and the second prints 2*i - 1 stars to form the pyramid.

loops
7short5 marks

Explain how an array is passed to a function.

Passing an Array to a Function

In C, an array is always passed by reference (address), not by value. When an array name is passed as an argument, only the address of its first element is sent to the function. Hence the function works on the original array, and any modification inside the function affects the caller's array.

Key points

  • The array name (e.g. arr) decays into a pointer to its first element.
  • The size is not passed automatically, so it is usually sent as a separate argument.
  • The function parameter can be declared as int a[] or int *a — both are equivalent.

Example

#include <stdio.h>

void printArray(int a[], int n) {   /* receives address */
    for (int i = 0; i < n; i++)
        printf("%d ", a[i]);
    printf("\n");
}

int main() {
    int arr[5] = {10, 20, 30, 40, 50};
    printArray(arr, 5);   /* pass array name and size */
    return 0;
}

Output: 10 20 30 40 50

For a 2-D array, all dimensions except the first must be specified, e.g. void f(int a[][3], int rows);

arrays
8short5 marks

Write a program to count the number of vowels in a given string.

Program: Count Vowels in a String

#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main() {
    char str[100];
    int i, count = 0;

    printf("Enter a string: ");
    gets(str);                 /* or fgets(str, sizeof(str), stdin); */

    for (i = 0; str[i] != '\0'; i++) {
        char ch = tolower(str[i]);
        if (ch == 'a' || ch == 'e' || ch == 'i' ||
            ch == 'o' || ch == 'u')
            count++;
    }

    printf("Number of vowels = %d\n", count);
    return 0;
}

Explanation: The loop scans each character until the null terminator '\0'. Each character is converted to lowercase with tolower() so both uppercase and lowercase vowels are counted, and count is incremented whenever the character is one of a, e, i, o, u.

Sample run:

Enter a string: Education
Number of vowels = 5
strings
9short5 marks

What is a self-referential structure? Explain with example.

Self-Referential Structure

A self-referential structure is a structure that contains at least one member which is a pointer to a structure of the same type. This pointer lets one structure variable point to (link to) another of the same kind, which is the basis for dynamic data structures such as linked lists, stacks, queues, and trees.

Syntax / Example

struct node {
    int data;             /* data part */
    struct node *next;    /* pointer to same structure type */
};

Here next is a pointer to struct node, so each node can hold a value and the address of the next node, forming a chain:

#include <stdio.h>
#include <stdlib.h>

struct node {
    int data;
    struct node *next;
};

int main() {
    struct node *head = malloc(sizeof(struct node));
    struct node *second = malloc(sizeof(struct node));

    head->data = 10;
    head->next = second;    /* link to next node */
    second->data = 20;
    second->next = NULL;    /* end of list */

    printf("%d -> %d\n", head->data, second->data);  /* 10 -> 20 */
    return 0;
}

Note: a structure cannot contain a variable of its own type (that would need infinite memory); it can only contain a pointer to its own type.

structures
10short5 marks

Explain the increment and decrement operators with pre and post forms.

Increment (++) and Decrement (--) Operators

These are unary operators that increase or decrease the value of a variable by 1.

  • ++a / a++ is equivalent to a = a + 1
  • --a / a-- is equivalent to a = a - 1

Each has two forms — prefix and postfix — which differ in when the change takes effect within an expression.

Prefix form (++a, --a)

The variable is first updated, then its new value is used in the expression. ("Change, then use.")

Postfix form (a++, a--)

The current value is used first in the expression, then the variable is updated. ("Use, then change.")

Example

int a = 5, b;
b = ++a;   /* a becomes 6, then b = 6  -> a=6, b=6 */

int x = 5, y;
y = x++;   /* y = 5 first, then x becomes 6 -> x=6, y=5 */
ExpressionResult
b = ++a; (a=5)a = 6, b = 6
y = x++; (x=5)x = 6, y = 5

When used as a standalone statement (e.g. a++; or ++a;), prefix and postfix give the same effect.

operators
11short5 marks

Write a program to find the sum of digits of a given number.

Program: Sum of Digits of a Number

#include <stdio.h>
int main() {
    int num, digit, sum = 0;

    printf("Enter a number: ");
    scanf("%d", &num);

    int n = num;
    if (n < 0) n = -n;          /* handle negative numbers */

    while (n != 0) {
        digit = n % 10;        /* extract last digit */
        sum += digit;          /* add to sum */
        n /= 10;               /* remove last digit */
    }

    printf("Sum of digits of %d = %d\n", num, sum);
    return 0;
}

Logic: The last digit is obtained with the modulus operation digit=nmod10\text{digit} = n \bmod 10, added to sum, and then removed using integer division n=n/10n = n / 10. The loop repeats until n=0n = 0.

Sample run:

Enter a number: 1234
Sum of digits of 1234 = 10
loops
12short5 marks

Write short notes on enumerated data type (enum).

Enumerated Data Type (enum)

An enumeration is a user-defined data type consisting of a set of named integer constants, which makes a program more readable by replacing plain numbers with meaningful names.

Syntax

enum tag_name { constant1, constant2, ... };

Key Points

  • By default the first constant is assigned the value 0, and each subsequent constant is one more than the previous.
  • Values can be set explicitly; following constants continue from there.
  • Internally, enum constants are stored as integers.

Example

#include <stdio.h>

enum week { SUN, MON, TUE, WED, THU, FRI, SAT };
/* SUN=0, MON=1, ... SAT=6 */

int main() {
    enum week today;
    today = WED;
    printf("Day number = %d\n", today);   /* prints 3 */
    return 0;
}

With explicit values:

enum color { RED = 1, GREEN, BLUE };   /* RED=1, GREEN=2, BLUE=3 */

Advantages: improves readability, makes code self-documenting, and is easier to maintain than using magic numbers.

data-types

Frequently asked questions

Where can I find the BSc CSIT (TU) C Programming (BSc CSIT, CSC115) question paper 2078?
The full BSc CSIT (TU) C Programming (BSc CSIT, CSC115) 2078 (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) 2078 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) 2078 paper?
The BSc CSIT (TU) C Programming (BSc CSIT, CSC115) 2078 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.