Unit 3 of MAKAUT C Programming (PPS-II) shifts focus from basic control flow to structured modular software design. Pointers, call-by-reference mechanics, storage classes (static, extern), and 1D array operations are heavily tested in both university semester examinations and campus technical interviews (TCS NQT, Cognizant, Wipro, LTIMindtree).

This guide unpacks the entire Unit 3 syllabus with clear stack activation frame diagrams, storage class memory tables, and 5+ solved high-scoring MAKAUT exam programs.

---

1. Modular Programming & Functions

A function is a self-contained block of statements designed to perform a specific task.

Components of a Function:

  1. Function Prototype: Informs compiler of function name, parameters, and return type before invocation.
  2. Function Definition: Contains actual executable code body.
  3. Function Call: Invokes the function, passing actual arguments and allocating a stack frame.

---

2. Storage Classes in C: auto, register, static, extern

Storage ClassLocationDefault Initial ValueScopeLifetime
`auto`Stack RAMGarbage ValueLocal to blockBlock execution duration
`register`CPU Register (if free)Garbage ValueLocal to blockBlock execution duration
`static`Data Segment (RAM)Zero (0)Local to blockRetained across function calls
`extern`Data Segment (RAM)Zero (0)Global across filesEntire application lifetime

---

3. Parameter Passing: Call by Value vs Call by Reference

c

Swapping Program: Call by Value vs Call by Reference

c

---

4. 1D Array Fundamentals & Pointer-Array Duality

An array stores elements of the same data type in contiguous memory locations.

Key Equivalences:

  • arr (array name) decays into pointer to first element (&arr[0]).
  • arr[i] \equiv *(arr + i).
  • &arr[i] \equiv (arr + i).

---

5. Solved High-Scoring MAKAUT Exam Programs

Program 1: Finding 2nd Largest & 2nd Smallest Array Elements (Single Pass O(N))

*Exam Context: Group B / Group C (10 Marks)*

c

---

Program 2: Merging Two Sorted Arrays into a Third Sorted Array

*Exam Context: Group C (10 Marks)*

c

---

Program 3: Adam Number Verification

An Adam Number is a number where the square of the reverse of the number equals the reverse of the square of the number (e.g., 12^2 = 144; reverse of 12 is 21; 21^2 = 441; reverse of 441 is 144).

c

---

6. Key Takeaways for Unit 3

  • Never return pointers to local automatic stack variables from a function. Local stack memory is deallocated upon function return, resulting in a dangling pointer.
  • Pass large arrays via pointers (const int *arr) to avoid overhead from copying array elements.