⚡ CCSU Meerut · BCA 1st Semester · Solved Question Paper
C Programming BCA-102 Dec 2023 / Jan 2024 Solved Question Paper
Complete authentic solved question paper for Chaudhary Charan Singh University (CCSU) BCA 1st Semester Programming Principle & Algorithm (BCA-102). Section A, B, and C with full model answers, code, and dry-run tables.
SECTION A : Very Short Answer Questions
All 5 questions are compulsory · 3 marks each (15 marks total)Q1 (a). Differentiate between a Variable and a Constant in C.
Model Answer:
- Variable: A named memory location whose value can be modified during program execution. Example:
int count = 10; count = 20; // Allowed - Constant: A fixed value that cannot be altered once defined. Created using the
constkeyword or#definepreprocessor directive. Example:const float PI = 3.14159;
Q1 (b). What is the purpose of the #include <stdio.h> header file?
Model Answer:
#include <stdio.h> is a preprocessor directive that tells the C preprocessor to copy the contents of the Standard Input Output header file into the source program before compilation. It contains the function prototypes and declarations for standard I/O library routines like printf(), scanf(), getchar(), and putchar().
Q1 (c). Explain the Conditional (Ternary) Operator with syntax.
Model Answer:
The conditional operator (? :) is the only ternary operator in C (requiring three operands). It works as a concise inline alternative to a simple if-else statement.
Syntax: condition ? expression_if_true : expression_if_false;
int a = 15, b = 20;
int max = (a > b) ? a : b; // max receives 20
Q1 (d). What is the difference between break and continue statements?
Model Answer:
break: Immediately terminates the innermost loop orswitchcase, transferring execution control to the statement following the loop block.continue: Skips the remaining statements inside the current iteration of the loop and immediately passes control to the next iteration condition check.
Q1 (e). What is an Array? Write its syntax of declaration and initialization.
Model Answer:
An Array is a derived, contiguous data structure that stores a fixed-size sequential collection of elements of the same data type under a single variable name.
int marks[5] = {85, 92, 78, 64, 90}; // Declaration & Initialization of 5 integers
SECTION B : Short Answer Questions
Attempt any 2 questions out of 3 · 7.5 marks each (15 marks total)Q2. Explain the difference between Prefix and Postfix increment operators with a dry-run table and C code.
Model Answer:
In C programming, the increment operator (++) adds 1 to its operand. It has two modes of operation depending on placement:
- Prefix Increment (
++x): Follows the principle "Increment First, Use Later". The value of the operand is increased by 1 before being used in the enclosing expression. - Postfix Increment (
x++): Follows the principle "Use First, Increment Later". The existing value of the operand is evaluated in the expression first, and then incremented by 1.
Dry Run Comparison (Initial value: x = 5):
| Statement | Step 1 | Step 2 | Final Values |
|---|---|---|---|
y = ++x; | x becomes 6 | y assigned 6 | x = 6, y = 6 |
y = x++; | y assigned 5 | x becomes 6 | x = 6, y = 5 |
#include <stdio.h>
int main() {
int x = 5, y = 5;
printf("Prefix ++x = %d\n", ++x); // Prints 6
printf("Postfix y++ = %d\n", y++); // Prints 5 (y becomes 6 afterwards)
printf("After postfix y = %d\n", y); // Prints 6
return 0;
}
Q3. What is Recursion? Write a recursive C function to calculate the Factorial of a given number.
Model Answer:
Recursion is a programming technique in which a function calls itself directly or indirectly to solve a smaller instance of the same problem. Every recursive function must contain two essential parts:
- Base Case: The terminating condition that stops further recursive calls and prevents stack overflow.
- Recursive Step: The statement where the function invokes itself with updated arguments moving closer to the base case.
#include <stdio.h>
// Recursive function definition
long factorial(int n) {
if (n <= 1) // Base Case
return 1;
else // Recursive Step
return n * factorial(n - 1);
}
int main() {
int num = 5;
printf("Factorial of %d is: %ld\n", num, factorial(num)); // Outputs 120
return 0;
}
Q4. Differentiate between Call by Value and Call by Reference parameter passing methods.
Model Answer:
| Feature | Call by Value | Call by Reference |
|---|---|---|
| Values Passed | Copy of the actual argument is passed | Memory address (pointer) is passed |
| Original Variables | Changes made in formal parameters do NOT affect actual values | Changes directly modify original variables |
| Memory | Allocates separate memory for formal parameters | Uses original variable's memory space |
SECTION C : Long Descriptive & Coding Questions
Attempt any 3 questions out of 5 · 15 marks each (45 marks total)Q5. Write a complete C program to multiply two 3x3 matrices. Explain the condition for matrix multiplication.
Model Answer:
Condition for Matrix Multiplication: Multiplication of two matrices \(A_{m \times k}\) and \(B_{k \times n}\) is only possible if the number of columns in the first matrix equals the number of rows in the second matrix. The resulting matrix \(C\) has dimensions \(m \times n\).
#include <stdio.h>
int main() {
int a[3][3], b[3][3], c[3][3];
int i, j, k;
printf("Enter elements of Matrix A (3x3):\n");
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
scanf("%d", &a[i][j]);
}
}
printf("Enter elements of Matrix B (3x3):\n");
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
scanf("%d", &b[i][j]);
}
}
// Matrix Multiplication logic using 3 nested loops
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
c[i][j] = 0;
for (k = 0; k < 3; k++) {
c[i][j] += a[i][k] * b[k][j];
}
}
}
printf("\nResultant Product Matrix C (3x3):\n");
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
printf("%d\t", c[i][j]);
}
printf("\n");
}
return 0;
}
Q6. What are Storage Classes in C? Explain auto, static, extern, and register storage classes in detail.
Model Answer:
A Storage Class defines the scope (visibility), lifetime (longevity), storage location (memory vs CPU register), and initial default value of a variable.
| Storage Class | Storage Location | Default Value | Scope | Lifetime |
|---|---|---|---|---|
auto | RAM (Stack) | Garbage | Local to block | Within block |
register | CPU Register | Garbage | Local to block | Within block |
static | RAM (Data segment) | Zero (0) | Local to block | Entire program run |
extern | RAM (Data segment) | Zero (0) | Global (all files) | Entire program run |
Q7. What are Pointers? Explain dynamic memory allocation functions: malloc(), calloc(), realloc(), and free().
Model Answer:
A Pointer is a variable that stores the memory address of another variable. Dynamic Memory Allocation allows memory to be allocated, resized, and released at runtime from the Heap Segment using functions declared in <stdlib.h>:
malloc(size): Allocates a single continuous block of raw memory of specified bytes. Memory contains garbage values. Syntax:int *ptr = (int*) malloc(5 * sizeof(int));calloc(n, size): Allocates multiple blocks of memory for an array of \(n\) elements and initializes all bytes to zero.realloc(ptr, new_size): Reallocates or alters the size of previously allocated memory without losing existing data.free(ptr): Releases allocated heap memory back to the operating system to prevent memory leaks.