Preparing for the BEU PPS 2024 Special Exam?
This post includes the complete Programming for Problem Solving (PPS) question paper from the BEU Special Exam 2024 with clear, unit-wise solutions. Ideal for 1st Semester CSE, ECE, and related branch students to revise core C programming concepts effectively.
Q.1 Choose the correct answer of the following :
(a) What would be the output of the following program?
int main()
{
float a = 3.15529;
printf("\n%6.2f", a);
}
(i) 3.16
(ii) 3.15
(iii) Compilation error
(iv) 3.15529
Answer:
(i) 3.16
Explanation: %6.2f
formats the float to 2 decimal places, rounding the third decimal. 3.15529
rounds to 3.16.
BEU PPS 2024 | Programming for Problem Solving PYQ with Solutions (1st Sem)
(b) Which of the following is true about argv
?
(i) It is an array of character pointers
(ii) It is a pointer to an array of character pointers
(iii) It is an array of strings
(iv) None of the above
Answer:
(i)It is an array of character pointers
Explanation: argv
(argument vector) is an array of pointers to strings (command-line arguments).
BEU PPS 2024 | Programming for Problem Solving PYQ with Solutions (1st Sem)
(c) What would be the output of the following program?
int main()
{
char *p = "Sanjay C-Test";
p[0] = 'a';
p[1] = 'b';
printf("%s", p);
}
(i) abnjay C-Test
(ii) Sanjay C-Test
(iii) Compile-time error
(iv) Run-time error
Answer:
(iv) Run-time error
Explanation: String literals are read-only. Modifying them causes undefined behavior (e.g., segmentation fault).
BEU PPS 2024 | Programming for Problem Solving PYQ with Solutions (1st Sem)
(d) Determine the output for the given program:
#include <stdio.h>
#define mul(x) x * 8
int main()
{
int y = mul(10 / 3);
printf("%d", y);
}
(i) 0
(ii) 24
(iii) 24.33
(iv) 26.64
Answer:
(ii) 24
Explanation: Macro expands to 10 / 3 * 8
. Integer division gives 3 * 8 = 24
.
BEU PPS 2024 | Programming for Problem Solving PYQ with Solutions (1st Sem)
(e) What would happen if you assign a value to an element of an array whose subscript exceeds the size of the array?
(i) The element will be set to 0
(ii) Nothing, it’s done all the time
(iii) Other data may be overwritten
(iv) Error message from the compiler
Answer:
(iii) Other data may be overwritten
Explanation: Writing out-of-bounds can corrupt adjacent memory (undefined behavior).
BEU PPS 2024 | Programming for Problem Solving PYQ with Solutions (1st Sem)
(f) What will be the output of the following C code?
int main()
{
signed char ch;
ch = 128;
printf("%d\n", ch);
return 0;
}
(i) 128
(ii) -128
(iii) Depends on the compiler
(iv) None of the above
Answer:
(ii) -128
Explanation: signed char
ranges from -128 to 127. 128
overflows to -128.
BEU PPS 2024 | Programming for Problem Solving PYQ with Solutions (1st Sem)
(g) The hexadecimal equivalent to the number (101101010010)₂ is:
(i) A53
(ii) A52
(iii) B52
(iv) C62
Answer:
(iii) B52
Explanation: Grouping into nibbles: 1011
(B), 0101
(5), 0010
(2) → B52.
BEU PPS 2024 | Programming for Problem Solving PYQ with Solutions (1st Sem)
(h) The correct syntax to send an array arr
as a parameter to a function func
is:
(i) func(arr)
(ii) func(&arr)
(iii) func(*arr)
(iv) func(arr[size])
Answer:
(i) func(arr)
Explanation: Arrays decay to pointers when passed to functions.
BEU PPS 2024 | Programming for Problem Solving PYQ with Solutions (1st Sem)
(i) A header file is:
(i) A file that contains standard library functions
(ii) A file that contains definitions and macros
(iii) A file that contains user-defined functions
(iv) A file that is present in current working directory
Answer:
(ii) Contains definitions and macros
Explanation: Header files hold declarations, macros, and constants.
BEU PPS 2024 | Programming for Problem Solving PYQ with Solutions (1st Sem)
(j) The expression = 7 / 22 * (3.14 + 2) * 3 / 5
evaluates to:
(i) 8.28
(ii) 6.28
(iii) 3.14
(iv) 0
Answer:
(iv) 0
Explanation: 7 / 22
is integer division (0). Entire expression evaluates to 0.
BEU PPS 2024 | Programming for Problem Solving PYQ with Solutions (1st Sem)
Q.2
(a) A 5-digit positive integer is entered through the keyboard. Write a recursive function to calculate the sum of digits of the given number.
Answer: Concept:
We will use recursion to break the number into digits and add them.
- Suppose the number is
12345
- We can split it like:
5 + sum of (1234)
Then again:4 + sum of (123)
And so on…
Base case:
If the number is 0
, return 0
.
Recursive case:
Return last digit + sum of remaining number
i.e., n % 10 + sum(n / 10)
C Code:
#include <stdio.h>
// Recursive function to calculate sum of digits
int sumOfDigits(int n) {
if (n == 0)
return 0;
else
return (n % 10) + sumOfDigits(n / 10);
}
int main() {
int num;
printf("Enter a 5-digit number: ");
scanf("%d", &num);
int result = sumOfDigits(num);
printf("Sum of digits = %d", result);
return 0;
}
Example Execution:
If input is: 12345
Then the function works like this:
→ 5 + sum(1234)
→ 5 + 4 + sum(123)
→ 5 + 4 + 3 + sum(12)
→ 5 + 4 + 3 + 2 + sum(1)
→ 5 + 4 + 3 + 2 + 1 = 15
(b) Explain compile-time and run-time initialization of arrays with suitable examples.
Answer:
Compile-time Initialization | Run-time Initialization |
---|---|
Values are assigned to array during declaration | Values are assigned to array during program execution |
Happens at the time of compilation | Happens at the time of execution (run-time) |
Suitable when values are already known | Suitable when values are to be taken from user/input device |
No need for user input | Requires user input using scanf() or similar |
Uses direct assignment syntax | Uses loops and input functions for assignment |
Example: int a[3] = {1, 2, 3}; | Example: See code below |
Example of Run-time Initialization:
#include <stdio.h>
int main() {
int a[5], i;
printf("Enter 5 elements:\n");
for(i = 0; i < 5; i++) {
scanf("%d", &a[i]); // Run-time input
}
printf("Array elements are:\n");
for(i = 0; i < 5; i++) {
printf("%d ", a[i]);
}
return 0;
}
Q.3
(a) Differentiate between entry and exit controlled loops with suitable examples (flowcharts).
Answer:
Entry Controlled Loop | Exit Controlled Loop |
---|---|
Condition is checked before entering the loop body | Condition is checked after executing the loop body once |
If the condition is false initially, loop body may not execute | Loop body executes at least once even if condition is false |
Common examples: for , while loops | Common example: do-while loop |
Syntax (while):while(condition) { statements; } | Syntax (do-while):do { statements; } while(condition); |
Used when we want to check the condition before any execution | Used when we want to guarantee one execution before checking |
Example of Entry Controlled Loop (while loop):
int i = 1;
while (i <= 5) {
printf("%d ", i);
i++;
}
Output: 1 2 3 4 5
Example of Exit Controlled Loop (do-while loop):
int i = 1;
do {
printf("%d ", i);
i++;
} while (i <= 5);
Output: 1 2 3 4 5
(b) Write a program in C to print the following pattern:
1
2 3
4 5 6
7 8 9 10…
Answer: Logic:

#include <stdio.h>
int main() {
int i, j, num = 1;
int rows;
printf("Enter number of rows: ");
scanf("%d", &rows);
for(i = 1; i <= rows; i++) {
for(j = 1; j <= i; j++) {
printf("%d ", num);
num++;
}
printf("\n");
}
return 0;
}
Sample Output (for rows = 4):
1
2 3
4 5 6
7 8 9 10
Q.4
(a) Sort the following numbers in ascending order 12, 6, 17, 4, 2, 9, 5 using insertion sort technique:.Give clear explanation for every pass.
Answer:
Initial Array:
12, 6, 17, 4, 2, 9, 5
Pass-wise Explanation:
- Pass 1: Insert 6
→ 6 < 12 → shift 12 → place 6
→ Result:6, 12, 17, 4, 2, 9, 5
- Pass 2: Insert 17
→ Already in correct position
→ Result:6, 12, 17, 4, 2, 9, 5
- Pass 3: Insert 4
→ Shift 17, 12, 6 → place 4
→ Result:4, 6, 12, 17, 2, 9, 5
- Pass 4: Insert 2
→ Shift 17, 12, 6, 4 → place 2
→ Result:2, 4, 6, 12, 17, 9, 5
- Pass 5: Insert 9
→ Shift 17, 12 → place 9
→ Result:2, 4, 6, 9, 12, 17, 5
- Pass 6: Insert 5
→ Shift 17, 12, 9, 6 → place 5
→ Result:2, 4, 5, 6, 9, 12, 17
Final Sorted Array:
2, 4, 5, 6, 9, 12, 17
(b) Write your own version of string manipulation functions xstrlen()
and xstrcpy()
to mimic standard library functions strlen()
and strcpy()
.
Answer:
1. xstrlen()
This function counts the number of characters in a string (excluding the null character \0
).
Code:
int xstrlen(char *str) {
int length = 0;
while (str[length] != '\0') {
length++;
}
return length;
}
2. xstrcpy()
This function copies the content of one string (source) into another string (destination).
Code:
void xstrcpy(char *dest, char *src) {
int i = 0;
while (src[i] != '\0') {
dest[i] = src[i];
i++;
}
dest[i] = '\0'; // Null terminator at the end
}
Example Usage:
#include <stdio.h>
int main() {
char source[] = "Hello";
char target[20];
printf("Length = %d\n", xstrlen(source));
xstrcpy(target, source);
printf("Copied String = %s\n", target);
return 0;
}
Q.5
(a) Write a program in C that converts a string like "124"
to an integer 124
.
Answer: Concept:
We need to convert a string of digits (e.g., "124"
) into an integer 124
.
This can be done by:
- Traversing the string from left to right
- For each character, subtract
'0'
to get its numeric value - Multiply the result by 10 and add the digit
C Program to Convert String to Integer
#include <stdio.h>
int main() {
char str[] = "124"; // String to convert
int i = 0;
int num = 0;
while (str[i] != '\0') {
num = num * 10 + (str[i] - '0'); // Convert char to int and add
i++;
}
printf("Converted number = %d", num);
return 0;
}
Output:
Converted number = 124
(b) Differentiate between structure and union. Write an example situation where union is more suitable than structure.
Answer:
Structure | Union |
---|---|
Allocates separate memory for each member | Allocates shared memory for all members |
All members can store values at the same time | Only one member can hold a value at a time |
Memory size = sum of sizes of all members | Memory size = size of the largest member |
Changing one member does not affect others | Changing one member affects the others |
Used when we need to store multiple data types together | Used when we store only one value at a time out of many |
Example Where Union is More Suitable:
Suppose we are designing a system to store sensor data where only one type of data is used at a time (temperature, pressure, or humidity):
union SensorData {
int temperature;
float pressure;
char humidity;
};
In this case, union saves memory because we don’t need to store all values at once.
Q.6
(a) Write a program in C to copy one file to another. While doing so, replace all lowercase characters with their equivalent uppercase characters.
Answer: Program in C to copy File with Lowercase to Uppercase
#include <stdio.h>
int main() {
FILE *f1, *f2;
char ch;
f1 = fopen("input.txt", "r");
f2 = fopen("output.txt", "w");
while ((ch = fgetc(f1)) != EOF) {
if (ch >= 'a' && ch <= 'z') {
ch = ch - 32; // Convert to uppercase
}
fputc(ch, f2);
}
fclose(f1);
fclose(f2);
return 0;
}
Explanation (In One Line Each):
- Open
input.txt
for reading. - Open
output.txt
for writing. - Read each character.
- If it’s lowercase (
a
–z
), convert to uppercase. - Write to new file.
- Close both files.
(b) What is the relation between array and pointer? What is an array of pointers? Explain with examples.
Answer: Relation Between Array and Pointer:
- In C, the name of an array acts like a pointer to its first element.
- That means, if you write
arr[0]
, it’s same as*(arr + 0)
- So,
arr
is similar to a constant pointer: it points to the first element of the array.
Example:
int arr[3] = {10, 20, 30};
printf("%d\n", arr[0]); // prints 10
printf("%d\n", *arr); // also prints 10
printf("%d\n", *(arr + 1)); // prints 20
What is an Array of Pointers?
- An array of pointers is a collection where each element is a pointer.
- Useful when each pointer points to different memory locations like strings or arrays.
Example:
#include <stdio.h>
int main() {
char *names[3] = {"Alice", "Bob", "Charlie"};
for (int i = 0; i < 3; i++) {
printf("%s\n", names[i]); // prints each name
}
return 0;
}
Here:
names[0]
points to"Alice"
names[1]
points to"Bob"
names[2]
points to"Charlie"
So names
is an array of 3 character pointers.
Q.7
(a) Multiple return
statements are allowed within a function, but a function cannot return more than one value.Explain this concept with an example.
Answer: In C language:
- A function can have multiple
return
statements, based on conditions or logic. - But it can return only one value at a time when it is called.
- If you need to return multiple values, you have to use pointers or structures.
Example: Function with multiple return statements
int checkNumber(int n) {
if (n > 0)
return 1; // Positive
else if (n < 0)
return -1; // Negative
else
return 0; // Zero
}
Explanation:
- This function returns:
1
if number is positive-1
if number is negative0
if number is zero
- But in one function call, only one return value is passed back.
Why it can’t return more than one value?
Because in C, function return type allows returning only:
- A single
int
,float
,char
, etc. - Or a
pointer
, or astructure
(as a whole)
Not multiple individual values.
(b) Differentiate between break
and continue
statements with examples.How does break
differ from exit()
?
Answer:
break Statement | continue Statement |
---|---|
Used to exit a loop or switch block immediately | Used to skip the current iteration of the loop |
Control moves outside the loop | Control moves to the next iteration of the loop |
Can be used in for , while , do-while , and switch | Can be used only in for , while , and do-while loops |
Example of break
:
for (int i = 1; i <= 5; i++) {
if (i == 3)
break;
printf("%d ", i);
}
Output: 1 2
Explanation: Loop stops when i == 3
Example of continue
:
for (int i = 1; i <= 5; i++) {
if (i == 3)
continue;
printf("%d ", i);
}
Output: 1 2 4 5
Explanation: i == 3
is skipped, rest executes
Difference between break
and exit()
:
break | exit() |
---|---|
Exits only the current loop or block | Exits the entire program immediately |
Used for loop control | Used to terminate the program |
Defined in loop/switch context | Defined in stdlib.h |
Example of exit()
:
#include <stdlib.h>
int main() {
printf("Hello\n");
exit(0); // Terminates program here
printf("World\n"); // This won't run
}
Output: Hello
Explanation: Program exits after exit(0)
and doesn’t print “World”
Q.8
(a) Explain call-by-value and call-by-reference with examples. Differentiate between null pointer and void pointer.
Answer:
1. Call-by-Value
- A copy of the variable’s value is passed to the function.
- Changes made inside the function do not affect the original variable.
Example:
void change(int x) {
x = x + 10;
}
int main() {
int a = 5;
change(a);
printf("%d", a); // Output: 5
}
2. Call-by-Reference
- The address of the variable is passed to the function.
- Changes made inside the function affect the original variable.
Example:
void change(int *x) {
*x = *x + 10;
}
int main() {
int a = 5;
change(&a);
printf("%d", a); // Output: 15
}
Difference between Null Pointer and Void Pointer
Null Pointer | Void Pointer |
---|---|
Points to nothing (NULL ) | Can point to any data type |
Used for safe initialization of unused pointers | Used as a generic pointer |
Cannot be dereferenced | Must be type-casted before dereferencing |
Example (Null):
int *ptr = NULL;
Example (Void):
void *ptr;
int a = 10;
ptr = &a;
printf("%d", *(int*)ptr);
(b) Write a program to find the greatest of three numbers entered through the keyboard:First using nested if-else construct and Then using conditional operator.
Answer:
1. Using Nested if-else:
#include <stdio.h>
int main() {
int a, b, c;
printf("Enter three numbers: ");
scanf("%d %d %d", &a, &b, &c);
if (a > b) {
if (a > c)
printf("Greatest = %d", a);
else
printf("Greatest = %d", c);
} else {
if (b > c)
printf("Greatest = %d", b);
else
printf("Greatest = %d", c);
}
return 0;
}
2. Using Ternary Operator:
#include <stdio.h>
int main() {
int a, b, c, max;
printf("Enter three numbers: ");
scanf("%d %d %d", &a, &b, &c);
max = (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c);
printf("Greatest = %d", max);
return 0;
}
Q.9
Write short notes on any two of the following:
(a) Pointer to an array
(b) Bitwise shift operators
(c) Linked list
(d) Dynamic allocation of memory
Answer:
(a) Pointer to an Array
- A pointer to an array points to the entire array, not just its first element.
- It is declared as:
int (*ptr)[5];
→ pointer to an array of 5 integers. - Useful when passing multi-dimensional arrays to functions.
Example:
int arr[5] = {1, 2, 3, 4, 5};
int (*ptr)[5] = &arr;
(b) Bitwise Shift Operators
- Used to shift bits of a number to the left (
<<
) or right (>>
). x << n
: Multipliesx
by 2ⁿx >> n
: Dividesx
by 2ⁿ (ignoring remainder)
Example:
int x = 4; // Binary: 0100
printf("%d", x << 1); // Output: 8 (1000)
(c) Linked List
- A dynamic data structure where each node contains data and a pointer to next node.
- Unlike arrays, linked lists do not require contiguous memory.
- Types: Singly, Doubly, Circular.
Example Node:
struct Node {
int data;
struct Node *next;
};
(d) Dynamic Allocation of Memory
- Memory is allocated at runtime using functions like
malloc()
,calloc()
,realloc()
, and freed usingfree()
. - Helps in creating flexible programs that use memory as needed.
Example:
int *p = (int*) malloc(5 * sizeof(int));
Conclusion
This guide covers unit-wise long answer solutions for the BEU PPS 2024 Special Exam, based on repeated PYQs and syllabus analysis. It’s designed to help 1st semester students revise effectively and score better in exams.
You May Also Like
- PPS 2023 pyq – BEU 1st Sem
- BEU Engineering Physics 2024-Most Repeated PYQs
- Important Questions for CSE 1st Sem – BEU
- NPTEL Assignment Solutions – Latest Updates
Stay Updated – Join Our Community
Get the latest updates, Engineering Physics PYQ solutions, model papers, and BEU study materials right on your phone.
👉 Join our WhatsApp Group – PrabhakarGuru Updates
Disclaimer
The questions and answers provided here are based on previous year trends and syllabus analysis. While we aim for accuracy, we do not guarantee that the same questions will appear in the actual BEU exams.
Besic electrical engineering