lastbench.online • Savitribai Phule Pune University

SAVITRIBAI PHULE PUNE UNIVERSITY (SPPU)

FIRST YEAR ENGINEERING (F.E.) — 2024 REVISED PATTERN (NEP-2020)

Course: Fundamentals of Programming Languages (FPL | COM108 / ESC-105-COM)
Official End-Semester & In-Semester Examination Model Solutions & PYQ Bank

Document ID: SPPU-FE-2024-FPL-PYQ-01 • Complete 11-Page Vector Edition with Official Syllabus Diagrams
Official SPPU Recommended Syllabus Literature (NEP-2020 ESC-105-COM): This master question bank strictly adheres to the canonical definitions, algorithms, and methods of the prescribed university textbooks: 1) Programming in ANSI C by E. Balagurusamy (Tata McGraw-Hill), 2) Fundamentals of Programming Languages by Nirali Prakashan (Dr. Nitin N. Sakhare, Dr. Hemantkumar B. Jadhav, SPPU 2024 Course), and 3) Schaum's Outline: Programming with C by Byron S. Gottfried (McGraw-Hill).
Examiner Weightage Note: Continuous Comprehensive Evaluation (CCE/In-Sem) comprises 30 Marks (Units I, II, III). End-Semester Examination (ESE) comprises 70 Marks (Units I through VI). Full 8-mark questions demand theoretical concept, formal syntax, complete ANSI C99 code, step-by-step dry-run tracing tables, and sample terminal I/O.
Unit I: Program Planning & C Programming Fundamentals In-Sem: 10M | End-Sem: 12M
Q1. Define Algorithm and Flowchart. Draw standard flowchart symbols with specific operational roles. Develop a step-by-step algorithm and complete flowchart to determine all real and complex roots of a quadratic equation (ax² + bx + c = 0). SPPU Dec 2023, May 2024 • 8 Marks

1. Core Algorithmic Principles & ISO Geometric Symbols

An algorithm is an ordered, deterministic, finite sequence of computational steps transforming formal input into unambiguous output. It must satisfy five fundamental criteria: Input (≥ 0), Output (≥ 1), Finiteness, Definiteness, and Feasibility.

Symbol NameGeometric ContourOperational FunctionC Counterpart
TerminalOval / Rounded RectangleMarks entry or exit boundary of routineint main() / return 0;
Input / OutputParallelogramReads data or writes computed resultsscanf() / printf()
ProcessRectangleArithmetic calculation, variable initializationD = b*b - 4*a*c;
DecisionDiamond (Rhombus)Evaluates Boolean condition for True/False branchesif (D >= 0)
ConnectorCircleJoins converging control flows on same pageLabels / goto anchors

2. Step-by-Step Quadratic Equation Algorithm

FIGURE 1.1: Official SPPU Canonical Flowchart — Real and Complex Roots of ax² + bx + c = 0 (E. Balagurusamy Ch. 2 / Nirali Prakashan)
START Read a, b, c D = (b * b) - (4 * a * c) D > 0 ? YES r1 = (-b + sqrt(D)) / (2*a) r2 = (-b - sqrt(D)) / (2*a) Print Real Roots r1, r2 NO D == 0 ? YES r1 = r2 = -b / (2*a) NO (D < 0) real = -b / (2*a) imag = sqrt(-D) / (2*a) Print real ± i * imag STOP
Q2. Explain the four Storage Classes in C (auto, register, static, extern) across 5 parameters. Write verified C code demonstrating lifetime retention of static variables versus auto variables across function invocations. SPPU Dec 2022, May 2023, Dec 2024 • 8 Marks
Storage ClassKeywordMemory SegmentDefault ValueScopeLifetime
AutomaticautoStack FrameGarbageLocal blockTill block exit
RegisterregisterCPU Register / StackGarbageLocal blockTill block exit
StaticstaticData Segment (BSS)Zero (0)Local to block/fileEntire program run
ExternalexternData SegmentZero (0)Global across filesEntire program run
FIGURE 2.1: ANSI C Process Memory Segment Architecture & Storage Mapping (E. Balagurusamy Ch. 9 / Nirali Prakashan)
STACK FRAME (auto variables | LIFO) HEAP (malloc / free dynamic memory) BSS SEGMENT (Uninitialized static/extern) DATA SEGMENT (Initialized static/extern) TEXT / CODE SEGMENT (Read-Only Machine Code) auto: Allocated on Stack frame. Local scope. Destroyed on block exit. Default: Garbage. register: Stored in CPU register (or stack fallback). Fast access, no &address allowed. static: Retained in BSS/Data segment throughout execution. Initialized once. Default: 0. extern: Stored in Data segment with external global linkage across all source files.
#include <stdio.h>

void executeScopeDemo() {
    auto int autoCounter = 1;     /* Re-created on stack upon each invocation */
    static int staticCounter = 1; /* Initialized ONCE in data segment; value persists */
    printf("autoCounter = %d | staticCounter = %d\n", autoCounter, staticCounter);
    autoCounter++;
    staticCounter++;
}

int main() {
    printf("Call 1: "); executeScopeDemo(); /* autoCounter = 1 | staticCounter = 1 */
    printf("Call 2: "); executeScopeDemo(); /* autoCounter = 1 | staticCounter = 2 */
    printf("Call 3: "); executeScopeDemo(); /* autoCounter = 1 | staticCounter = 3 */
    return 0;
}
Unit II: Operators and Expressions In-Sem: 10M | End-Sem: 10M
Q3. Explain Bitwise Operators in C with truth tables (&, |, ^, ~, <<, >>). For operands a = 12 and b = 25, compute: a & b, a | b, a ^ b, a << 2, and b >> 2 with binary arithmetic steps. SPPU May 2019, Dec 2023, May 2024 • 7 Marks

Operand binary representations in 8-bit notation: a = 12 = 00001100_2, b = 25 = 00011001_2.

Unit III: Control Structures (Branching & Iteration) In-Sem: 10M | End-Sem: 12M
Q4. Compare while, do-while, and for loops across 5 structural criteria. Write a complete C program to check whether a given integer is an Armstrong Number with a step-by-step dry-run trace table for input 153. SPPU Dec 2019, May 2023, Dec 2024 • 8 Marks
#include <stdio.h>

int main() {
    int num, originalNum, remainder, accumulatedSum = 0;
    printf("Enter a 3-digit positive integer: ");
    if (scanf("%d", &num) != 1 || num < 0) return 1;
    
    originalNum = num;
    while (originalNum != 0) {
        remainder = originalNum % 10;                         /* Extract terminal digit */
        accumulatedSum += (remainder * remainder * remainder); /* Cube and accumulate */
        originalNum /= 10;                                    /* Truncate terminal digit */
    }
    
    if (accumulatedSum == num)
        printf("%d is an Armstrong Number.\n", num);
    else
        printf("%d is NOT an Armstrong Number.\n", num);
    return 0;
}
IterationoriginalNum (Start)remainder (% 10)Cube ComputedaccumulatedSumoriginalNum (End)
Iteration 115333³ = 270 + 27 = 2715
Iteration 21555³ = 12527 + 125 = 1521
Iteration 3111³ = 1152 + 1 = 1530 (Terminates)
Unit IV: Arrays and String Manipulation End-Sem Weightage: 14M
Q5. Write a complete C program to perform Matrix Multiplication of two matrices A (r1 x c1) and B (r2 x c2). State the mandatory dimension compatibility condition and explain the triple-nested loop architecture. SPPU Dec 2022, May 2023, May 2024 • 8 Marks
#include <stdio.h>
#define MAX 10

int main() {
    int a[MAX][MAX], b[MAX][MAX], result[MAX][MAX];
    int r1, c1, r2, c2, i, j, k;
    printf("Enter Matrix A rows and columns: "); scanf("%d %d", &r1, &c1);
    printf("Enter Matrix B rows and columns: "); scanf("%d %d", &r2, &c2);
    
    /* Dimensional Compatibility Check */
    if (c1 != r2) {
        printf("Error: Matrix multiplication undefined (cols of A != rows of B).\n");
        return 1;
    }
    
    /* Input Matrix A and B omitted for brevity */
    for (i = 0; i < r1; i++) {
        for (j = 0; j < c2; j++) {
            result[i][j] = 0; /* Reset dot product accumulator */
            for (k = 0; k < c1; k++) {
                result[i][j] += a[i][k] * b[k][j];
            }
        }
    }
    return 0;
}
Unit V: Modular Programming & User-Defined Functions End-Sem Weightage: 14M
Q6. Differentiate Call by Value versus Call by Reference (Address) with stack memory diagrams. Write two C functions demonstrating why variable swapping fails in Call by Value and succeeds in Call by Reference. SPPU Dec 2019, May 2022, May 2024 • 8 Marks
Evaluation ParameterCall by ValueCall by Reference (Pointers)
Mechanism of PassageValue copies of actual parameters passedMemory addresses (&a, &b) passed
Caller Variable ModificationChanges in callee do NOT affect callerChanges in callee directly modify caller memory
Stack AllocationAllocates duplicate variables on stackOperates via pointer indirection (*ptr)
Memory OverheadProportional to data structure sizeFixed 4 or 8 bytes per address pointer
#include <stdio.h>

/* FAILS: Call by Value (Modifies local stack copies only) */
void swapByValue(int x, int y) {
    int temp = x; x = y; y = temp;
}

/* SUCCEEDS: Call by Reference (Dereferences caller memory addresses) */
void swapByReference(int *x, int *y) {
    int temp = *x; *x = *y; *y = temp;
}

int main() {
    int a = 10, b = 20;
    swapByValue(a, b);
    printf("After Value: a = %d, b = %d (UNALTERED)\n", a, b);
    swapByReference(&a, &b);
    printf("After Reference: a = %d, b = %d (SWAPPED)\n", a, b);
    return 0;
}
FIGURE 5.1: Call by Value vs. Call by Reference Stack Memory Activation Frames (E. Balagurusamy Ch. 9 / Schaum's)
A) CALL BY VALUE (Copying -- Fails to Swap) main() Frame: a = 10 [0x1000] | b = 20 [0x1004] copies values (10, 20) swapByValue(): x = 10 [0x2000] | y = 20 [0x2004] * x and y swapped locally inside callee stack frame. * Callee destroyed on return. Caller a & b remain 10, 20. B) CALL BY REFERENCE (Address Passing -- Succeeds) main() Frame: a = 10 [0x1000] | b = 20 [0x1004] swapByRef(): *x = 0x1000 | *y = 0x1004 * Pointers dereference caller memory directly via *x and *y. * Values permanently swapped in caller: a = 20, b = 10.
Unit VI: Structures, Unions & File Operations End-Sem Weightage: 16M
Q7. Differentiate Structure (struct) versus Union (union) across 6 parameters with memory allocation layout diagrams. Write a C program demonstrating data corruption in Union due to memory sharing. SPPU Dec 2020, May 2023, Dec 2024 • 8 Marks
Evaluation CriterionStructure (struct)Union (union)
Keywordstructunion
Memory AllocationSum of sizes of all individual members (+ padding)Size of the LARGEST member only
Starting OffsetEach member has a distinct memory addressAll members share the exact same starting address
ConcurrencyAll members retain valid data simultaneouslyOnly ONE member can hold valid data at any instant
Data Overwrite RiskWriting to one member has no effect on othersWriting to one member overwrites other members
FIGURE 6.1: Memory Allocation Architecture — struct vs. union (E. Balagurusamy Chapter 10)
A) struct Student { int roll_no; char name[20]; float marks; }; → Total Allocated = 26 Bytes roll_no (2B) Bytes 0..1 name[20] (20 Bytes Contiguous Buffer) Bytes 2..21 marks (4B) Bytes 22..25 B) union Data { int roll_no; char name[20]; float marks; }; → Total Allocated = 20 Bytes (Largest Member) SHARED MEMORY BASE: 0x1000 (name[20] spans full 20 bytes) roll_no (0..1) marks (0..3 overlapping) ← Modifying marks overwrites bytes 0..3 of name[20]!
#include <stdio.h>

struct Student {
    int rollNo;
    char name[32];
    float marks[3];
    float percentage;
};

int main() {
    struct Student students[5]; int topperIndex = 0;
    for (int i = 0; i < 5; i++) {
        printf("\nEnter Record for Student %d:\n", i + 1);
        scanf("%d %s", &students[i].rollNo, students[i].name);
        float total = 0;
        for (int j = 0; j < 3; j++) {
            scanf("%f", &students[i].marks[j]);
            total += students[i].marks[j];
        }
        students[i].percentage = total / 3.0f;
        if (students[i].percentage > students[topperIndex].percentage) topperIndex = i;
    }
    printf("\nTOPPER: Roll: %d, Name: %s, Percentage: %.2f%%\n",
           students[topperIndex].rollNo, students[topperIndex].name, students[topperIndex].percentage);
    return 0;
}