← Back to Semester 1 Hub
University CCSU Meerut
Course & Code BCA-102
Subject C Programming
Exam Session Dec 2023 / Jan 2024
Maximum Marks 75 Marks
Time Duration 3 Hours

SECTION A : Very Short Answer Questions

All 5 questions are compulsory · 3 marks each (15 marks total)
15 Marks

Q1 (a). Differentiate between a Variable and a Constant in C.

🔥 Repeated: 2020, 2022, 2023 3 Marks

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 const keyword or #define preprocessor directive. Example: const float PI = 3.14159;
Examiner Tip: Writing one line of code example for both is mandatory to secure full 3/3 marks.

Q1 (b). What is the purpose of the #include <stdio.h> header file?

🔥 Repeated: 2021, 2023 3 Marks

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.

🔥 Repeated: 2019, 2022, 2023 3 Marks

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?

🔥 Repeated: 2020, 2021, 2023 3 Marks

Model Answer:

  • break: Immediately terminates the innermost loop or switch case, 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.

🔥 Repeated: 2021, 2023 3 Marks

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)
15 Marks

Q2. Explain the difference between Prefix and Postfix increment operators with a dry-run table and C code.

🔥 Repeated: 2020, 2022, 2023 7.5 Marks

Model Answer:

In C programming, the increment operator (++) adds 1 to its operand. It has two modes of operation depending on placement:

  1. 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.
  2. 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):

StatementStep 1Step 2Final Values
y = ++x;x becomes 6y assigned 6x = 6, y = 6
y = x++;y assigned 5x becomes 6x = 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.

🔥 Repeated: 2021, 2023 7.5 Marks

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.

🔥 Repeated: 2020, 2022, 2023 7.5 Marks

Model Answer:

FeatureCall by ValueCall by Reference
Values PassedCopy of the actual argument is passedMemory address (pointer) is passed
Original VariablesChanges made in formal parameters do NOT affect actual valuesChanges directly modify original variables
MemoryAllocates separate memory for formal parametersUses original variable's memory space

SECTION C : Long Descriptive & Coding Questions

Attempt any 3 questions out of 5 · 15 marks each (45 marks total)
45 Marks

Q5. Write a complete C program to multiply two 3x3 matrices. Explain the condition for matrix multiplication.

🔥 High Weightage Question 15 Marks

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;
}
Complexity Analysis: Time Complexity of standard \(3 \times 3\) matrix multiplication is \(O(n^3)\) due to three nested loops. Space Complexity is \(O(n^2)\) to store the product matrix.

Q6. What are Storage Classes in C? Explain auto, static, extern, and register storage classes in detail.

🔥 Repeated: 2021, 2023 15 Marks

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 ClassStorage LocationDefault ValueScopeLifetime
autoRAM (Stack)GarbageLocal to blockWithin block
registerCPU RegisterGarbageLocal to blockWithin block
staticRAM (Data segment)Zero (0)Local to blockEntire program run
externRAM (Data segment)Zero (0)Global (all files)Entire program run

Q7. What are Pointers? Explain dynamic memory allocation functions: malloc(), calloc(), realloc(), and free().

🔥 Guaranteed 15 Marks Topic 15 Marks

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.