Browse papers
A

Section A: Long Answer Questions

Attempt any TWO questions.

3 questions·10 marks each
1long10 marks

Explain the structure of a C program. Discuss different categories of operators in C with suitable examples.

Structure of a C Program

A C program is made up of the following sections, normally in this order:

  1. Documentation section — comments (/* ... */ or //) describing the program.
  2. Preprocessor / Link section — header file inclusion such as #include <stdio.h>.
  3. Definition section — symbolic constants and macros, e.g. #define PI 3.14.
  4. Global declaration section — global variables and function prototypes.
  5. main() function — the entry point; execution begins here. It contains a declaration part (local variables) and an executable part (statements) enclosed in { }.
  6. Sub-program (user-defined functions) section — definitions of the functions called from main().
#include <stdio.h>      /* link section   */
#define PI 3.14159       /* definition      */
float area(float r);     /* global decl.    */
int main() {             /* main function   */
    float r = 2.0;
    printf("Area = %f\n", area(r));
    return 0;
}
float area(float r) {    /* sub-program     */
    return PI * r * r;
}

Categories of Operators in C

CategoryOperatorsExample
Arithmetic+ - * / %c = a + b;
Relational< > <= >= == !=a > b
Logical&& || !a>0 && b>0
Assignment= += -= *= /= %=a += 5;
Increment/Decrement++ --a++; --b;
Bitwise& | ^ ~ << >>a & b
Conditional (ternary)?:max = a>b ? a : b;
Specialsizeof, & (address), * (deref), , (comma), . , ->sizeof(int)

Example using several operators:

int a = 10, b = 3, r;
r = a % b;              /* arithmetic: r = 1      */
int big = (a > b) ? a : b;  /* conditional: big = 10 */
printf("%d %d\n", r, big);

Each category serves a distinct purpose: arithmetic for computation, relational and logical for decision-making, bitwise for low-level manipulation, and special operators for memory and type operations.

program-structure
2long10 marks

What is a function? Explain types of functions based on arguments and return value. Differentiate call by value and call by reference.

Function

A function is a self-contained, named block of code that performs a specific task. It promotes modularity, code reuse, and easier debugging. A function has a declaration (prototype), a definition, and is invoked by a call.

returnType name(parameterList);   /* prototype */
returnType name(parameterList) {  /* definition */ ... }
name(arguments);                  /* call */

Types of Functions (based on arguments and return value)

  1. No argument, no return value — performs a task but neither receives nor returns data.
    void greet() { printf("Hello\n"); }
    
  2. With argument, no return value — receives input but returns nothing.
    void show(int n) { printf("%d\n", n); }
    
  3. No argument, with return value — returns a value but takes no input.
    int getNum() { return 10; }
    
  4. With argument, with return value — receives input and returns a result (most common).
    int add(int a, int b) { return a + b; }
    

Call by Value vs Call by Reference

Call by ValueCall by Reference
A copy of the actual argument's value is passedThe address of the actual argument is passed
Formal parameters are ordinary variablesFormal parameters are pointers
Changes inside the function do not affect the caller's variablesChanges inside the function do affect the caller's variables
Safer; original data protectedAllows the function to modify caller data; needed to return multiple values
void swapVal(int a, int b){ int t=a; a=b; b=t; }      /* no effect on caller */
void swapRef(int *a, int *b){ int t=*a; *a=*b; *b=t; } /* swaps caller's values */
/* Call: swapVal(x, y);   swapRef(&x, &y); */
functions
3long10 marks

Define structure and union. Write a program using an array of structures to store and display employee details (id, name, salary).

Structure

A structure is a user-defined data type that groups together variables of different data types under a single name. Each member gets its own memory location, so the size of a structure is (at least) the sum of its members' sizes.

struct employee { int id; char name[30]; float salary; };

Union

A union is similar to a structure but all members share the same memory location; its size equals that of its largest member. Only one member holds a meaningful value at a time. Unions save memory when only one field is needed at once.

union data { int i; float f; char c; };  /* size = max(member sizes) */

Key difference: in a structure every member has separate storage (all usable simultaneously), whereas in a union all members overlap in one memory block (only one usable at a time).

Program: array of structures (employee details)

#include <stdio.h>

struct employee {
    int id;
    char name[30];
    float salary;
};

int main() {
    int n, i;
    struct employee emp[100];

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

    for (i = 0; i < n; i++) {
        printf("Enter id, name, salary of employee %d: ", i + 1);
        scanf("%d %s %f", &emp[i].id, emp[i].name, &emp[i].salary);
    }

    printf("\n--- Employee Details ---\n");
    printf("ID\tName\t\tSalary\n");
    for (i = 0; i < n; i++) {
        printf("%d\t%s\t\t%.2f\n", emp[i].id, emp[i].name, emp[i].salary);
    }
    return 0;
}

The array emp stores n records; member access uses the dot (.) operator, e.g. emp[i].salary.

structures
B

Section B: Short Answer Questions

Attempt any EIGHT questions.

9 questions·5 marks each
4short5 marks

Differentiate between high-level and low-level languages.

BasisHigh-Level LanguageLow-Level Language
MeaningEnglish-like, human-readable language (C, C++, Java)Machine-oriented language (machine code / assembly)
ClosenessClose to the programmer/problem domainClose to the hardware
TranslationNeeds a compiler or interpreterMachine code needs none; assembly needs an assembler
PortabilityPortable across machinesMachine-dependent (not portable)
Ease of useEasy to write, read, and debugDifficult, error-prone
Execution speedGenerally slower (extra translation)Very fast and memory-efficient
Hardware controlLimited direct controlFull, direct control of hardware/registers

In short, high-level languages favour programmer productivity and portability, while low-level languages favour speed and direct hardware access.

fundamentals
5short5 marks

Explain the switch-case statement with an example.

switch-case Statement

The switch statement is a multi-way decision (selection) statement that compares the value of an integer/character expression against several case constants and executes the matching block. It is a cleaner alternative to a long if-else-if ladder.

Syntax:

switch (expression) {
    case constant1: statements; break;
    case constant2: statements; break;
    default: statements;
}

Rules: the expression must evaluate to an integer or character; each case label must be a constant and unique; break exits the switch (without it, execution falls through to the next case); default is optional and runs when no case matches.

Example:

#include <stdio.h>
int main() {
    int day = 3;
    switch (day) {
        case 1: printf("Sunday\n");   break;
        case 2: printf("Monday\n");   break;
        case 3: printf("Tuesday\n");  break;
        default: printf("Other day\n");
    }
    return 0;
}

Output: Tuesday

control-flow
6short5 marks

Write a program to sort an array of n numbers in ascending order.

Program: Sort n numbers in ascending order (Bubble Sort)

#include <stdio.h>

int main() {
    int n, i, j, temp;
    int a[100];

    printf("Enter how many numbers: ");
    scanf("%d", &n);

    printf("Enter %d numbers: ", n);
    for (i = 0; i < n; i++)
        scanf("%d", &a[i]);

    /* Bubble sort */
    for (i = 0; i < n - 1; i++) {
        for (j = 0; j < n - 1 - i; j++) {
            if (a[j] > a[j + 1]) {   /* swap if out of order */
                temp     = a[j];
                a[j]     = a[j + 1];
                a[j + 1] = temp;
            }
        }
    }

    printf("Sorted (ascending): ");
    for (i = 0; i < n; i++)
        printf("%d ", a[i]);
    printf("\n");
    return 0;
}

The nested loops repeatedly compare adjacent elements and swap them when the left element is larger, so after each outer pass the largest remaining element "bubbles" to the end, yielding an ascending order.

arrays
7short5 marks

Explain the difference between getch(), getche() and getchar().

getch(), getche() and getchar()

All three read a single character from the keyboard, but differ in echoing and the need for Enter.

FunctionHeaderEchoes char to screen?Needs Enter?Buffered?
getch()<conio.h>No (input hidden)No (reads immediately)No
getche()<conio.h>YesNo (reads immediately)No
getchar()<stdio.h>YesYes (waits for Enter)Yes
  • getch() — reads a character without displaying it; commonly used for passwords or "press any key" pauses.
  • getche() — reads a character and echoes (displays) it on screen, without waiting for Enter.
  • getchar() — standard C library function; reads one character from the buffered standard input and requires the Enter key. It is portable, whereas getch()/getche() belong to the non-standard <conio.h> (Turbo C / Windows).
char c1 = getch();    /* typed char not shown */
char c2 = getche();   /* typed char shown     */
char c3 = getchar();  /* type char then Enter */
io-functions
8short5 marks

Write a program to count the number of words in a string.

Program: Count the number of words in a string

A word is counted at each transition from a space to a non-space character.

#include <stdio.h>

int main() {
    char str[200];
    int i, words = 0;
    int inWord = 0;   /* flag: currently inside a word? */

    printf("Enter a string: ");
    fgets(str, sizeof(str), stdin);   /* reads line incl. spaces */

    for (i = 0; str[i] != '\0'; i++) {
        if (str[i] == ' ' || str[i] == '\n' || str[i] == '\t') {
            inWord = 0;
        } else if (inWord == 0) {
            inWord = 1;   /* start of a new word */
            words++;
        }
    }

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

Sample run: input C programming is fun → output Number of words = 4.

The inWord flag ensures multiple consecutive spaces are not miscounted as extra words.

strings
9short5 marks

What is recursion? List its advantages and disadvantages.

Recursion

Recursion is a programming technique in which a function calls itself (directly or indirectly) to solve a problem by breaking it into smaller sub-problems of the same kind. Every recursive function must have a base case (a terminating condition) and a recursive case; without a base case it would call itself infinitely.

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

Advantages

  • Makes code shorter, cleaner, and more readable for problems that are naturally recursive (factorial, Fibonacci, Tower of Hanoi, tree traversals).
  • Reduces the need for complex loops and auxiliary variables.
  • Directly mirrors mathematical/divide-and-conquer definitions.

Disadvantages

  • High memory usage — each call adds a frame to the stack; deep recursion can cause stack overflow.
  • Slower due to the overhead of repeated function calls.
  • Can be harder to trace/debug and may recompute sub-problems (e.g. naive Fibonacci), making it inefficient compared to an equivalent iterative solution.
recursion
10short5 marks

Explain dynamic memory allocation functions in C.

Dynamic Memory Allocation (DMA) in C

Dynamic memory allocation is the process of allocating memory at run time from the heap, allowing programs to request exactly the amount of memory needed. The functions are declared in <stdlib.h> and return a void* (cast as required); they return NULL on failure.

FunctionPurpose
malloc(size)Allocates a single block of size bytes; memory is uninitialized (garbage).
calloc(n, size)Allocates memory for n elements of size bytes each and initializes all bytes to 0.
realloc(ptr, newSize)Resizes a previously allocated block to newSize bytes, preserving existing contents.
free(ptr)Releases allocated memory back to the heap to prevent memory leaks.
int *p;
p = (int *) malloc(5 * sizeof(int));   /* 5 uninitialized ints */
if (p == NULL) { printf("No memory\n"); return 1; }

p = (int *) realloc(p, 10 * sizeof(int)); /* grow to 10 ints */

free(p);   /* always free when done */

Note: calloc is equivalent to malloc followed by zeroing; every successful allocation must be matched by a free.

memory
11short5 marks

Write a program to read and write a structure record to a file.

Program: Write and read a structure record to/from a file

This uses binary file I/O with fwrite() and fread().

#include <stdio.h>

struct student {
    int    roll;
    char   name[30];
    float  marks;
};

int main() {
    struct student s = {0}, r = {0};
    FILE *fp;

    /* --- Take input --- */
    printf("Enter roll, name, marks: ");
    scanf("%d %s %f", &s.roll, s.name, &s.marks);

    /* --- Write record to file --- */
    fp = fopen("student.dat", "wb");
    if (fp == NULL) { printf("File error\n"); return 1; }
    fwrite(&s, sizeof(struct student), 1, fp);
    fclose(fp);

    /* --- Read record back from file --- */
    fp = fopen("student.dat", "rb");
    if (fp == NULL) { printf("File error\n"); return 1; }
    fread(&r, sizeof(struct student), 1, fp);
    fclose(fp);

    printf("\nRecord read from file:\n");
    printf("Roll: %d, Name: %s, Marks: %.2f\n", r.roll, r.name, r.marks);
    return 0;
}

fwrite() writes sizeof(struct student) bytes of the record to the binary file opened in "wb" mode; fread() reads the same block back in "rb" mode. Always check fopen for NULL and close files with fclose().

files
12short5 marks

Write short notes on the comma operator.

Short Note: The Comma Operator

The comma operator (,) is a binary operator that lets two (or more) expressions be evaluated where syntactically only one expression is allowed. It evaluates its left operand first (discarding the result), then evaluates its right operand, and the value of the whole expression is the value of the rightmost operand. It has the lowest precedence of all C operators and guarantees left-to-right evaluation order.

Example:

int a, b, c;
c = (a = 2, b = 3, a + b);   /* a=2, b=3, then c = a+b = 5 */
printf("%d\n", c);          /* prints 5 */

Common use — multiple expressions in a for loop:

for (i = 0, j = n - 1; i < j; i++, j--) {
    /* initialize and update two variables together */
}

Note: the comma that separates function arguments or variable declarations (e.g. int a, b;) is a separator, not the comma operator.

operators

Frequently asked questions

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