BSc CSIT (TU) Science C Programming (BSc CSIT, CSC115) Question Paper 2080 Nepal
This is the official BSc CSIT (TU) (Science stream) C Programming (BSc CSIT, CSC115) question paper for 2080, as set in the regular annual examination. It carries 60 full marks and a time allowance of 180 minutes, across 12 questions. On Kekkei you can attempt this C Programming (BSc CSIT, CSC115) past paper online with a timer, get instant AI feedback and step-by-step solutions, and track the topics where you lose marks — completely free. Whether you are revising for your BSc CSIT (TU) C Programming (BSc CSIT, CSC115) exam or solving previous years' question papers, this 2080 paper is a great way to practise under real exam conditions.
Section A: Long Answer Questions
Attempt any TWO questions.
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:
- Documentation section — comments (
/* ... */or//) describing the program. - Preprocessor / Link section — header file inclusion such as
#include <stdio.h>. - Definition section — symbolic constants and macros, e.g.
#define PI 3.14. - Global declaration section — global variables and function prototypes.
main()function — the entry point; execution begins here. It contains a declaration part (local variables) and an executable part (statements) enclosed in{ }.- 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
| Category | Operators | Example |
|---|---|---|
| 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; |
| Special | sizeof, & (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.
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)
- No argument, no return value — performs a task but neither receives nor returns data.
void greet() { printf("Hello\n"); } - With argument, no return value — receives input but returns nothing.
void show(int n) { printf("%d\n", n); } - No argument, with return value — returns a value but takes no input.
int getNum() { return 10; } - 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 Value | Call by Reference |
|---|---|
| A copy of the actual argument's value is passed | The address of the actual argument is passed |
| Formal parameters are ordinary variables | Formal parameters are pointers |
| Changes inside the function do not affect the caller's variables | Changes inside the function do affect the caller's variables |
| Safer; original data protected | Allows 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); */
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.
Section B: Short Answer Questions
Attempt any EIGHT questions.
Differentiate between high-level and low-level languages.
| Basis | High-Level Language | Low-Level Language |
|---|---|---|
| Meaning | English-like, human-readable language (C, C++, Java) | Machine-oriented language (machine code / assembly) |
| Closeness | Close to the programmer/problem domain | Close to the hardware |
| Translation | Needs a compiler or interpreter | Machine code needs none; assembly needs an assembler |
| Portability | Portable across machines | Machine-dependent (not portable) |
| Ease of use | Easy to write, read, and debug | Difficult, error-prone |
| Execution speed | Generally slower (extra translation) | Very fast and memory-efficient |
| Hardware control | Limited direct control | Full, 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.
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
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.
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.
| Function | Header | Echoes char to screen? | Needs Enter? | Buffered? |
|---|---|---|---|---|
getch() | <conio.h> | No (input hidden) | No (reads immediately) | No |
getche() | <conio.h> | Yes | No (reads immediately) | No |
getchar() | <stdio.h> | Yes | Yes (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, whereasgetch()/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 */
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.
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.
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.
| Function | Purpose |
|---|---|
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.
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().
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.
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.