Browse papers
A

Section A: Long Answer Questions

Attempt any TWO questions.

3 questions·10 marks each
1long10 marks

Discuss the structure of a C program with a suitable example. Explain the compilation and execution process of a C program.

Structure of a C Program

A C program is built from the following sections, in order:

  1. Documentation section — comments describing the program (/* ... */ or //).
  2. Preprocessor/link section — header file inclusion, e.g. #include <stdio.h>.
  3. Definition section — symbolic constants/macros, e.g. #define PI 3.14159.
  4. Global declaration section — global variables and function prototypes.
  5. main() function — the entry point; execution begins here.
  6. User-defined functions — sub-programs called from main() or other functions.

Example

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

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

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

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

Compilation and Execution Process

A C source file (.c) passes through four stages before it can run:

  1. Preprocessing — the preprocessor expands #include, #define and other directives, producing an expanded source (.i).
  2. Compilation — the compiler translates the expanded source into assembly/object code (.obj/.o) after checking syntax.
  3. Linking — the linker combines the object code with library functions (e.g. printf from the standard library) and other object files to produce an executable (.exe/a.out).
  4. Loading and Execution — the loader loads the executable into memory and the CPU executes it, starting from main().
source.c → [Preprocessor] → source.i → [Compiler] → source.obj
         → [Linker + libraries] → a.out → [Loader] → Output

Using GCC: gcc program.c -o program performs preprocess, compile and link; ./program loads and runs it.

program-structure
2long10 marks

What is a loop? Explain different types of looping statements available in C with syntax, flowchart and examples.

Loop

A loop is a control structure that repeatedly executes a block of statements as long as a given condition remains true. Loops avoid code repetition and are used for iteration. C provides three looping statements.

1. for loop

Used when the number of iterations is known. The control flow checks the condition first (entry-controlled).

Syntax

for (initialization; condition; update) {
    // body
}

Flowchart (described): initialization → test condition → if true, execute body → update → back to test; if false, exit.

Example

for (int i = 1; i <= 5; i++)
    printf("%d ", i);   // 1 2 3 4 5

2. while loop

Entry-controlled; the condition is tested before each iteration. Used when iteration count is not known in advance.

Syntax

while (condition) {
    // body
}

Flowchart (described): test condition → if true, execute body → back to test; if false, exit.

Example

int i = 1;
while (i <= 5) { printf("%d ", i); i++; }

3. do-while loop

Exit-controlled; the body executes once before the condition is tested, so it always runs at least once.

Syntax

do {
    // body
} while (condition);

Flowchart (described): execute body → test condition → if true, repeat; if false, exit.

Example

int i = 1;
do { printf("%d ", i); i++; } while (i <= 5);

Summary

LoopCondition checkedMin. executions
forbefore body0
whilebefore body0
do-whileafter body1
loops
3long10 marks

Write a program to read N integers into an array and find the largest, smallest and average of the entered numbers.

Program: Largest, Smallest and Average of N Numbers

#include <stdio.h>

int main(void) {
    int n, a[100];
    int largest, smallest;
    long sum = 0;
    float average;

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

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

    largest = smallest = a[0];      /* assume first as both */
    for (int i = 0; i < n; i++) {
        if (a[i] > largest)  largest  = a[i];
        if (a[i] < smallest) smallest = a[i];
        sum += a[i];
    }

    average = (float) sum / n;

    printf("Largest  = %d\n", largest);
    printf("Smallest = %d\n", smallest);
    printf("Average  = %.2f\n", average);
    return 0;
}

How it works

  • The numbers are read into the array a using a for loop.
  • largest and smallest are initialized to the first element, then updated while traversing the array.
  • sum accumulates the total; average = sum / n (cast to float for a fractional result).

Sample Output

Enter how many numbers (N): 5
Enter 5 integers:
12 7 25 3 18
Largest  = 25
Smallest = 3
Average  = 13.00
arrays
B

Section B: Short Answer Questions

Attempt any EIGHT questions.

9 questions·5 marks each
4short5 marks

List the different types of operators in C and explain any four of them.

Operators in C

C provides the following categories of operators:

  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, & (address-of), * (dereference), , (comma)

Explanation of four operators

  • Arithmetic operator: performs mathematical operations. % gives the remainder. e.g. 7 % 31, 7 / 23 (integer division).
  • Relational operator: compares two values and yields 1 (true) or 0 (false). e.g. 5 > 31.
  • Logical operator: combines conditions. && is true only if both operands are true. e.g. (a > 0 && a < 10).
  • Conditional (ternary) operator: cond ? expr1 : expr2 returns expr1 if cond is true else expr2. e.g. max = (a > b) ? a : b;.
operators
5short5 marks

Differentiate between break and continue statements with examples.

break vs continue

Featurebreakcontinue
PurposeTerminates the loop/switch entirelySkips the rest of the current iteration only
EffectControl jumps out of the loopControl jumps to the next iteration
Used inloops and switchloops only

break example

for (int i = 1; i <= 5; i++) {
    if (i == 3) break;   // loop stops when i == 3
    printf("%d ", i);    // Output: 1 2
}

continue example

for (int i = 1; i <= 5; i++) {
    if (i == 3) continue; // skips printing 3
    printf("%d ", i);     // Output: 1 2 4 5
}

Summary: break exits the loop completely, whereas continue only skips the remaining statements of the current pass and continues with the next iteration.

control-flow
6short5 marks

Explain formatted input and output functions in C.

Formatted Input and Output in C

Formatted I/O uses format specifiers to control how data is read or displayed, allowing precise type and width control.

Formatted Output — printf()

Writes formatted data to the standard output.

printf("format string", arg1, arg2, ...);

Example:

int n = 42; float x = 3.14159;
printf("n = %d, x = %.2f\n", n, x);   // n = 42, x = 3.14

Formatted Input — scanf()

Reads formatted data from the standard input into variables (which must be passed by address using &).

scanf("format string", &var1, &var2, ...);

Example:

int age; float salary;
scanf("%d %f", &age, &salary);

Common format specifiers

SpecifierData type
%dint
%ffloat
%lfdouble
%cchar
%sstring
%xhexadecimal

Width/precision can be added, e.g. %6.2f prints a float in a field of 6 with 2 decimals.

io-functions
7short5 marks

What is a function? Explain the advantages of using functions in a program.

Function

A function is a self-contained, named block of code that performs a specific task. A program can call a function whenever that task is needed. C has library functions (e.g. printf) and user-defined functions, each having a prototype (declaration), definition and call.

int add(int a, int b) {   // definition
    return a + b;
}
// call: result = add(3, 4);

Advantages of using functions

  1. Modularity / divide-and-conquer: a large problem is split into smaller, manageable sub-tasks.
  2. Code reusability: a function written once can be called many times, avoiding repetition.
  3. Easier debugging and maintenance: errors are localized to individual functions.
  4. Reduced program size: repeated code is replaced by a single function and its calls.
  5. Readability: programs become well-organized and easier to understand.
  6. Reusability across programs: functions can be placed in libraries and shared.
functions
8short5 marks

Write a program to check whether a given number is prime or not.

Program: Check Whether a Number is Prime

A prime number is a natural number greater than 1 having exactly two divisors: 1 and itself.

#include <stdio.h>

int main(void) {
    int n, isPrime = 1;   /* assume prime */

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

    if (n <= 1) {
        isPrime = 0;                 /* 0,1 and negatives are not prime */
    } else {
        for (int i = 2; i <= n / 2; i++) {
            if (n % i == 0) {        /* divisible -> not prime */
                isPrime = 0;
                break;
            }
        }
    }

    if (isPrime)
        printf("%d is a prime number.\n", n);
    else
        printf("%d is not a prime number.\n", n);
    return 0;
}

Logic

  • Numbers <= 1 are not prime.
  • Otherwise, test divisibility from 2 up to n/2 (or sqrt(n) for efficiency). If any divisor divides n exactly, it is not prime.

Sample Output

Enter a number: 17
17 is a prime number.
loops
9short5 marks

Differentiate between while and do-while loops with examples.

while vs do-while

Featurewhile loopdo-while loop
TypeEntry-controlledExit-controlled
Condition testedBefore executing the bodyAfter executing the body
Minimum executions0 (may not run at all)1 (always runs once)
Syntax endingno semicolon after blockends with ; after while(...)

while example

int i = 5;
while (i < 5) {        // condition false -> body never runs
    printf("%d ", i);
    i++;
}                      // Output: (nothing)

do-while example

int i = 5;
do {                   // body runs once before test
    printf("%d ", i);
    i++;
} while (i < 5);       // Output: 5

Summary: A while loop checks the condition first and may execute zero times, whereas a do-while loop executes its body at least once because the condition is checked at the end.

loops
10short5 marks

Explain the concept of an array with example. How is a one-dimensional array declared and initialized?

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; each element is accessed using an index (subscript) starting from 0. Arrays let us handle many related values with a single name.

One-Dimensional Array

Declaration

data_type array_name[size];
int marks[5];        /* an array of 5 integers */

Initialization

int marks[5] = {90, 85, 70, 60, 95};   /* full initialization */
int a[5] = {1, 2};                     /* rest set to 0 */
int b[]  = {10, 20, 30};               /* size inferred = 3 */

Accessing elements (indices 0 to size-1):

printf("%d", marks[0]);   // first element = 90
marks[2] = 75;            // modify third element

Example

int a[3] = {5, 10, 15};
int sum = 0;
for (int i = 0; i < 3; i++)
    sum += a[i];          // sum = 30

Here marks[0] is the first element and marks[4] the last; valid indices range from 0 to 4.

arrays
11short5 marks

What is a pointer? Explain how a pointer variable is declared and initialized.

Pointer

A pointer is a variable that stores the memory address of another variable. Through a pointer we can indirectly access and modify the value stored at that address. Pointers enable dynamic memory allocation, efficient array/string handling, call-by-reference and building data structures.

Declaration

data_type *pointer_name;
int *p;       /* p can hold the address of an int */

The * indicates that the variable is a pointer; its base type must match the variable it points to.

Initialization

A pointer is initialized with the address of a variable using the address-of operator &:

int x = 10;
int *p;
p = &x;        /* p now holds the address of x */

Can also be combined: int *p = &x;.

Accessing the value

The dereference (indirection) operator * accesses the value at the stored address:

printf("%d", *p);   // prints 10 (value of x)
*p = 20;            // changes x to 20

A pointer that points to nothing should be set to NULL: int *p = NULL;.

pointers
12short5 marks

Write short notes on storage classes in C.

Storage Classes in C

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

1. auto

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

2. register

  • Requests the variable be stored in a CPU register for fast access (compiler may ignore).
  • Scope: local. Lifetime: block. Default value: garbage. The & operator cannot be applied.
register int counter;

3. static

  • Retains its value between function calls; initialized only once.
  • Scope: local (or file scope for globals). Lifetime: entire program. Stored in: memory. Default value: 0.
static int count = 0;  // keeps its value across calls

4. extern

  • Declares a global variable defined elsewhere (in another file or later in the same file); used to share variables across files.
  • Scope: global. Lifetime: entire program. Default value: 0.
extern int total;  // defined in another file

Summary

ClassScopeLifetimeDefaultStorage
autoblockblockgarbagestack
registerblockblockgarbageregister
staticblock/fileprogram0memory
externglobalprogram0memory
storage-class

Frequently asked questions

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