Browse papers
A

Section A: Long Answer Questions

Attempt any TWO questions.

3 questions·10 marks each
1long10 marks

List the different types of operators in C and explain any four of them. Write a program to demonstrate the use of bitwise operators.

Types of Operators in C

C provides a rich set of operators, grouped as follows:

  1. Arithmetic operators+, -, *, /, %
  2. Relational operators<, >, <=, >=, ==, !=
  3. Logical operators&&, ||, !
  4. Assignment operators=, +=, -=, *=, /=, %=
  5. Increment / Decrement operators++, --
  6. Bitwise operators&, |, ^, ~, <<, >>
  7. Conditional (ternary) operator?:
  8. Special operatorssizeof, , (comma), & (address-of), * (dereference), . and -> (member access)

Explanation of any four

  • Arithmetic operators perform basic mathematical computation. % (modulus) gives the remainder and works only with integers, e.g. 7 % 3 is 1. The / operator performs integer division when both operands are integers (7/2 is 3).
  • Relational operators compare two operands and yield 1 (true) or 0 (false), e.g. a > b. They are commonly used in if and loop conditions.
  • Logical operators combine relational expressions. && is true only when both sides are true; || is true when at least one side is true; ! reverses the truth value. They use short-circuit evaluation.
  • Bitwise operators operate on the individual bits of integer operands: & (AND), | (OR), ^ (XOR), ~ (one's complement), << (left shift), >> (right shift). For example, 5 & 3 is 1, and 1 << 3 is 8.

Program demonstrating bitwise operators

#include <stdio.h>

int main() {
    int a = 12, b = 10;   /* a = 1100, b = 1010 in binary */

    printf("a & b  = %d\n", a & b);   /* AND  -> 1000 = 8  */
    printf("a | b  = %d\n", a | b);   /* OR   -> 1110 = 14 */
    printf("a ^ b  = %d\n", a ^ b);   /* XOR  -> 0110 = 6  */
    printf("~a     = %d\n", ~a);      /* NOT  -> -13       */
    printf("a << 1 = %d\n", a << 1);  /* left shift  -> 24 */
    printf("a >> 1 = %d\n", a >> 1);  /* right shift -> 6  */

    return 0;
}

Sample output:

a & b  = 8
a | b  = 14
a ^ b  = 6
~a     = -13
a << 1 = 24
a >> 1 = 6

Here a << 1 multiplies a by 2 and a >> 1 divides a by 2, illustrating that shifts are fast equivalents of multiplication/division by powers of two.

operators
2long10 marks

What are the characteristics of an array? Write a program to input the age of 500 persons and display the number of persons in different age groups.

Characteristics of an Array

  • An array is a collection of elements of the same data type stored in contiguous memory locations.
  • Elements are accessed using an index/subscript that starts from 0 and goes up to n-1 for an array of size n.
  • The size is fixed at declaration time (for static arrays) and cannot grow at run time.
  • The name of the array acts as a constant pointer to its first element, so arr is equivalent to &arr[0].
  • Elements are stored sequentially, so the address of any element can be computed as base_address + index * size_of_element, giving constant-time random access.

Program: age groups of 500 persons

We read 500 ages and count how many fall in each group: 0–18, 19–35, 36–60, and above 60.

#include <stdio.h>

int main() {
    int age[500];
    int i;
    int g1 = 0, g2 = 0, g3 = 0, g4 = 0;  /* counters for each group */

    /* Input ages */
    for (i = 0; i < 500; i++) {
        printf("Enter age of person %d: ", i + 1);
        scanf("%d", &age[i]);
    }

    /* Classify into groups */
    for (i = 0; i < 500; i++) {
        if (age[i] <= 18)
            g1++;
        else if (age[i] <= 35)
            g2++;
        else if (age[i] <= 60)
            g3++;
        else
            g4++;
    }

    printf("\nAge group 0-18  : %d persons\n", g1);
    printf("Age group 19-35 : %d persons\n", g2);
    printf("Age group 36-60 : %d persons\n", g3);
    printf("Age group 60+   : %d persons\n", g4);

    return 0;
}

The array stores all 500 ages, a single pass classifies each age into the correct range using an if-else if ladder, and the four counters hold the result for each group.

arrays
3long10 marks

Explain call by reference. Write a program to swap two values using call by reference and discuss the role of pointers.

Call by Reference

In call by reference, instead of passing the values of the arguments, the addresses (references) of the actual arguments are passed to the function. The function receives these addresses in pointer parameters. Because the function works directly on the original memory locations, any change it makes is reflected back in the caller. This is in contrast to call by value, where copies are passed and the original variables remain unchanged.

Role of pointers

C implements call by reference using pointers. The & (address-of) operator obtains the address of a variable, and the * (dereference) operator accesses or modifies the value stored at that address. Pointers therefore let a function reach back into the caller's variables, which is essential for returning multiple results, modifying arrays/structures efficiently, and avoiding the overhead of copying large data.

Program: swap two values using call by reference

#include <stdio.h>

void swap(int *x, int *y) {   /* x and y hold addresses */
    int temp;
    temp = *x;   /* value at x  */
    *x = *y;     /* copy value at y into location x */
    *y = temp;
}

int main() {
    int a = 5, b = 10;

    printf("Before swap: a = %d, b = %d\n", a, b);
    swap(&a, &b);          /* pass addresses of a and b */
    printf("After swap : a = %d, b = %d\n", a, b);

    return 0;
}

Output:

Before swap: a = 5, b = 10
After swap : a = 10, b = 5

Here swap receives the addresses of a and b. By dereferencing the pointers (*x, *y) it exchanges the actual values, so the swap is visible in main. If the same function were written with call by value, the original a and b would stay unchanged.

pointers
B

Section B: Short Answer Questions

Attempt any EIGHT questions.

9 questions·5 marks each
4short5 marks

Explain the basic structure of a C program.

Basic Structure of a C Program

A typical C program is organized into the following sections, in order:

  1. Documentation section — comments giving the program name, author and purpose (e.g. /* ... */).
  2. Preprocessor / link section#include directives to attach header files (e.g. #include <stdio.h>).
  3. Definition section — symbolic constants and macros using #define.
  4. Global declaration section — global variables and function prototypes visible throughout the program.
  5. main() function — the entry point where execution begins; it contains declarations and executable statements enclosed in { }.
  6. Sub-program / user-defined function section — definitions of other functions called from main().

Example

#include <stdio.h>          /* link section */
#define PI 3.1416           /* definition section */

float area(float r);        /* global declaration / prototype */

int main() {                /* main function */
    float r = 5;
    printf("Area = %.2f\n", area(r));
    return 0;
}

float area(float r) {       /* user-defined function */
    return PI * r * r;
}

Every C program must contain exactly one main() function, which is where execution starts and normally ends.

program-structure
5short5 marks

Describe different formatted input and output functions in C.

Formatted Input and Output Functions in C

Formatted I/O functions use format specifiers (such as %d, %f, %c, %s) to control how data is read or displayed. They are declared in <stdio.h>.

Formatted output — printf()

Sends formatted data to the standard output (screen).

printf("format string", arg1, arg2, ...);
printf("Name = %s, Age = %d, GPA = %.2f\n", name, age, gpa);

Common specifiers: %d (int), %f (float), %c (char), %s (string), %x (hex). Width and precision can be set, e.g. %6.2f prints a float in a field of width 6 with 2 decimals.

Formatted input — scanf()

Reads formatted data from the standard input (keyboard) and stores it at the addresses of the variables (hence the &).

scanf("format string", &var1, &var2, ...);
scanf("%d %f", &n, &x);

It skips white space between numeric inputs and returns the number of items successfully read.

Related formatted functions

  • fprintf() / fscanf() — formatted I/O to and from a file stream.
  • sprintf() / sscanf() — formatted I/O to and from a character array (string) in memory.

These complement the unformatted functions (getchar, putchar, gets, puts) which transfer data without format specifiers.

io-functions
6short5 marks

Write a program to display the first 50 prime numbers.

Program: First 50 Prime Numbers

A prime number is a natural number greater than 1 that is divisible only by 1 and itself. We test each candidate by checking divisibility up to its square root and keep printing until we have found 50 primes.

#include <stdio.h>

int main() {
    int count = 0;   /* primes found so far */
    int num = 2;     /* candidate number     */

    printf("First 50 prime numbers:\n");

    while (count < 50) {
        int isPrime = 1, i;
        for (i = 2; i * i <= num; i++) {
            if (num % i == 0) {
                isPrime = 0;   /* divisor found -> not prime */
                break;
            }
        }
        if (isPrime) {
            printf("%d ", num);
            count++;
        }
        num++;
    }
    printf("\n");

    return 0;
}

Output (first few): 2 3 5 7 11 13 17 19 23 29 ... up to the 50th prime, which is 229.

The outer while loop continues until 50 primes are printed, and the inner for loop checks primality only up to num\sqrt{num} for efficiency.

loops
7short5 marks

Demonstrate the use of a recursive function with a suitable example.

Recursive Function

A recursive function is a function that calls itself, directly or indirectly, to solve a problem by reducing it to smaller instances of the same problem. Every recursion must have:

  1. A base case that stops the recursion, and
  2. A recursive case that moves toward the base case.

Example: Factorial

The factorial is defined as n!=n×(n1)!n! = n \times (n-1)! with the base case 0!=10! = 1.

#include <stdio.h>

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

int main() {
    int n = 5;
    printf("%d! = %ld\n", n, factorial(n));
    return 0;
}

Output: 5! = 120

How it works: factorial(5) = 5 * factorial(4) = 5 * 4 * factorial(3) = ... = 5 * 4 * 3 * 2 * 1 = 120. Each call is placed on the stack until the base case factorial(1) returns, after which the results unwind and multiply together.

recursion
8short5 marks

Create a structure called STUDENT with data members SID, name, address and CGPA, and write a program to initialize the values of 100 students.

Program: STUDENT Structure for 100 Students

We declare a structure STUDENT with the required members and use an array of 100 such structures to store and initialize the records.

#include <stdio.h>

struct STUDENT {
    int   SID;
    char  name[50];
    char  address[50];
    float CGPA;
};

int main() {
    struct STUDENT s[100];
    int i;

    /* Initialize the values of 100 students */
    for (i = 0; i < 100; i++) {
        printf("Enter SID, name, address, CGPA of student %d:\n", i + 1);
        scanf("%d", &s[i].SID);
        scanf("%s", s[i].name);
        scanf("%s", s[i].address);
        scanf("%f", &s[i].CGPA);
    }

    /* Display the stored records */
    printf("\n--- Student Records ---\n");
    for (i = 0; i < 100; i++) {
        printf("%d\t%s\t%s\t%.2f\n",
               s[i].SID, s[i].name, s[i].address, s[i].CGPA);
    }

    return 0;
}

Here struct STUDENT groups four related fields of different types into one record. The array s[100] holds 100 such records, the first loop initializes each member using scanf, and the second loop displays them. Members are accessed with the dot operator (s[i].SID).

structures
9short5 marks

Differentiate between while and do-while loops.

Difference between while and do-while Loops

Featurewhile loopdo-while loop
TypeEntry-controlled (pre-tested)Exit-controlled (post-tested)
Condition checkTested before the body executesTested after the body executes
Minimum executionsBody may run 0 times if condition is initially falseBody runs at least once
Syntax terminatorNo semicolon after the blockRequires a semicolon after while(condition);

Syntax

/* while */
while (condition) {
    /* body */
}

/* do-while */
do {
    /* body */
} while (condition);

Example

int i = 5;
while (i < 5) { printf("A"); i++; }   /* prints nothing  */

int j = 5;
do { printf("B"); j++; } while (j < 5); /* prints B once   */

The key distinction: a while loop may not run at all, whereas a do-while loop always executes its body at least once because the condition is checked only afterwards.

loops
10short5 marks

Explain the use of pointers with arrays.

Pointers with Arrays

In C, the name of an array is a constant pointer to its first element, i.e. arr is equivalent to &arr[0]. This close relationship lets us traverse and manipulate arrays using pointers.

Key points

  • arr[i] is exactly equivalent to *(arr + i), and &arr[i] is the same as arr + i.
  • Adding 1 to a pointer advances it by sizeof(element) bytes (pointer arithmetic), so it moves to the next element regardless of type.
  • Passing an array to a function actually passes a pointer to its first element, which is why functions can modify array contents (call by reference) and why the array size must be passed separately.

Example

#include <stdio.h>

int main() {
    int arr[5] = {10, 20, 30, 40, 50};
    int *p = arr;        /* p points to arr[0] */
    int i;

    for (i = 0; i < 5; i++) {
        printf("%d ", *(p + i));   /* same as arr[i] */
    }
    printf("\n");

    return 0;
}

Output: 10 20 30 40 50

Here p holds the base address of the array, and *(p + i) dereferences successive elements using pointer arithmetic, demonstrating that array indexing and pointer access are interchangeable.

pointers
11short5 marks

Write a program to find whether a string is a palindrome.

Program: Check Whether a String is a Palindrome

A string is a palindrome if it reads the same forwards and backwards (e.g. madam, level). We compare characters from both ends moving inward.

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

int main() {
    char str[100];
    int i, len, isPalindrome = 1;

    printf("Enter a string: ");
    scanf("%s", str);

    len = strlen(str);

    for (i = 0; i < len / 2; i++) {
        if (str[i] != str[len - 1 - i]) {
            isPalindrome = 0;   /* mismatch found */
            break;
        }
    }

    if (isPalindrome)
        printf("\"%s\" is a palindrome.\n", str);
    else
        printf("\"%s\" is not a palindrome.\n", str);

    return 0;
}

Sample runs:

Enter a string: madam
"madam" is a palindrome.

Enter a string: hello
"hello" is not a palindrome.

The loop compares str[i] with its mirror character str[len-1-i]; if every pair matches up to the middle, the string is a palindrome.

strings
12short5 marks

Write short notes on storage classes in C.

Storage Classes in C

A storage class defines the scope (visibility), lifetime (duration), default initial value, and storage location of a variable. C has four storage classes:

1. auto

  • Default for all local variables declared inside a block.
  • Scope: local to the block; Lifetime: until the block ends; Default value: garbage; Stored in: memory (stack).
  • Example: auto int x; (same as int x;).

2. register

  • Suggests storing the variable in a CPU register for faster access (the compiler may ignore the hint).
  • Scope: local; Lifetime: block; Default value: garbage. The address-of operator & cannot be used on it.
  • Example: register int counter;

3. static

  • A local static variable retains its value between function calls; a global static limits visibility to its source file.
  • Lifetime: entire program; Default value: zero; Stored in: memory.
  • Example: static int count = 0;

4. extern

  • Declares a global variable defined elsewhere (in another file or later in the same file), allowing it to be shared across files.
  • Scope: global (whole program); Lifetime: entire program; Default value: zero.
  • Example: extern int total;
Storage classScopeLifetimeDefault value
autoLocalBlockGarbage
registerLocalBlockGarbage
staticLocal/FileWhole programZero
externGlobalWhole programZero
storage-class

Frequently asked questions

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