BE Computer Engineering (Pokhara University) Programming in C (PU, CMP 124) Question Paper 2079
This is the official BE Computer Engineering (Pokhara University) Programming in C (PU, CMP 124) question paper for 2079, as set in the regular annual examination. It carries 100 full marks and a time allowance of 180 minutes, across 12 questions. On Kekkei you can attempt this Programming in C (PU, CMP 124) 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 BE Computer Engineering (Pokhara University) Programming in C (PU, CMP 124) exam or solving previous years' question papers, this 2079 paper is a great way to practise under real exam conditions.
Section A: Long Answer Questions
Attempt all / any as specified.
(a) Explain the basic structure of a C program with the help of a suitable example, clearly identifying the preprocessor directives, the main() function, declaration section and the executable statements. (6)
(b) Differentiate between the following pairs of data types in C, stating the typical size and range of each on a 32-bit system: (i) int vs unsigned int and (ii) float vs double. Explain what is meant by type conversion and distinguish between implicit and explicit (type-casting) conversion with one example each. (6)
(a) What is recursion? Differentiate between recursion and iteration in terms of memory usage and execution speed. (4)
(b) Write a C program using a recursive function to compute the factorial of a non-negative integer n entered by the user. Show how the recursive calls are placed on and removed from the stack for the input n = 4. (6)
(c) Explain call by value and call by reference with a C example of a swap() function for each, and state which one actually exchanges the values of the caller's variables and why. (4)
(a) What is a pointer? Explain the & (address-of) and * (dereference) operators with a short program that prints the address and value of a variable using a pointer. (5)
(b) Explain the relationship between arrays and pointers in C. Given the declaration int a[5];, show how a[i] can be accessed using pointer notation. (4)
(c) Describe the use of the functions malloc(), calloc(), realloc() and free() for dynamic memory management. Write a C program that dynamically allocates memory for n integers, reads them, and prints their sum. (5)
(a) Define a structure Student containing the members roll (integer), name (character array) and marks (float). Write a C program that reads the records of n students and writes them to a file named students.dat, then reads the records back from the file and displays them. (7)
(b) Differentiate between a structure and a union in C with respect to memory allocation, using a suitable example. (3)
Section B: Short Answer Questions
Attempt all / any as specified.
Differentiate between while and do-while loops. Write a C program using a loop to check whether a given integer is a prime number.
Evaluate the following C expressions, given int a = 5, b = 2, c; and state the value of the result and of any modified variable in each case:
(a) c = a++ + ++b;
(b) c = a % b + a / b;
(c) c = (a > b) ? a : b;
Also explain the difference between the = and == operators.
Write a C program that reads a string from the user and counts the number of vowels, consonants and spaces in it without using any built-in string library function.
Write a C program to find the largest and the second largest element in a one-dimensional array of n integers entered by the user.
Differentiate between the break and continue statements with a suitable example of each. Write a C program using nested loops to print the following pattern:
1
1 2
1 2 3
1 2 3 4
Explain how a two-dimensional array is stored in memory in C (row-major order). Write a C program to read a 3 x 3 matrix and find the sum of its diagonal elements.
List the different file opening modes in C (r, w, a, r+, w+, a+) and explain the purpose of each. State the difference between a text file and a binary file.
Write short notes on any THREE of the following:
(a) Storage classes in C (auto, register, static, extern)
(b) The C preprocessor and #define macros
(c) Difference between getchar()/putchar() and scanf()/printf()
(d) Enumerated data type (enum)