BE Computer Engineering (Pokhara University) Programming in C (PU, CMP 124) Question Paper 2078
This is the official BE Computer Engineering (Pokhara University) Programming in C (PU, CMP 124) question paper for 2078, as set in the regular annual examination. It carries 100 full marks and a time allowance of 180 minutes, across 11 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 2078 paper is a great way to practise under real exam conditions.
Section A: Long Answer Questions
Attempt all / any as specified.
(a) With the help of a neat diagram, explain the basic structure of a C program, clearly describing the role of the preprocessor directives, the main() function, declaration section and the executable statements. (6)
(b) Distinguish between int, float, double and char data types in C in terms of their typical size (in bytes) and range. Write a C program that reads a Celsius temperature from the user and prints the equivalent Fahrenheit temperature, using appropriate data types and format specifiers. (6)
(a) Differentiate between the while, do...while and for looping constructs in C with their general syntax and a suitable example of each. State clearly the situation in which a do...while loop is preferred. (7)
(b) Write a C program using a switch...case statement that behaves as a simple calculator. The program should read two operands and an operator (+, -, *, /) from the user and display the result. Handle the division-by-zero case appropriately. (7)
(a) What is recursion? Explain the concept of a recursive function with the help of the factorial example, and discuss how it differs from an iterative solution in terms of memory and the function call stack. (6)
(b) Write a C program that uses a user-defined function to search for a given element in a one-dimensional integer array using the linear search technique. The function should return the index of the element if found, or -1 otherwise. (8)
(a) What is a pointer? Explain the meaning of the & (address-of) and * (dereference) operators with a suitable example showing how a pointer is declared, initialized and used to modify the value of a variable. (6)
(b) Explain the difference between malloc() and calloc(). Write a C program that dynamically allocates memory for n integers (where n is entered by the user), reads them, prints their sum, and finally frees the allocated memory. (6)
Section B: Short Answer Questions
Attempt all / any as specified.
Explain the difference between the logical operators (&&, ||, !) and the bitwise operators (&, |, ^) in C. Evaluate the expression a = 5 + 3 * 2 - 8 / 4 step by step using operator precedence and show the final value of a.
Write a C program that reads a string from the user (without using the built-in strlen() function) and counts the number of vowels, consonants and spaces present in it.
Differentiate between call by value and call by reference in C with a suitable example. Illustrate by writing a function swap() that successfully exchanges the values of two variables passed from main().
(a) How does a structure differ from a union in terms of memory allocation? (2)
(b) Define a structure Student having members roll (integer), name (string) and marks (float). Write a C program to read details of 3 students into an array of structures and display the name of the student with the highest marks. (4)
Explain the different modes (r, w, a) used to open a file in C. Write a C program that opens a text file named data.txt, writes the numbers from 1 to 10 into it, and then closes the file, checking for any error during file opening.
Write a C program to check whether a given positive integer entered by the user is a prime number or not, and display an appropriate message.
Write short notes on any TWO of the following: (a) Storage classes in C (auto, static, register, extern); (b) #define macros versus constant variables; (c) Type conversion and type casting in C.