optional · CSS study notes
P-I.II. Programming Fundamentals
⬆️ Back to: Computer Science
🧭
Study route: open a topic → learn its three outcomes → read the foundation checks and worked examples → answer the self-test without notes → attempt its past-paper questions.
All 15 topic pages now use memory hooks, shorter notes, structured answers and recall checklists. The 48 recorded written references, 7 MCQs and 152 topic-page code blocks are retained; selected errors and missing answer keys have been corrected.
📜
Chapter scope from your syllabus pages: programming elements; problem solving and program design; systematic problem definition; language components and types; development and execution; source-to-executable conversion; program structure and data types; local/global/shared variables; standard I/O; control structures; functions and parameter passing; library functions; arrays, pointers and strings; structures, unions and bit manipulation.
🗣️
In simple words: define the problem, translate it into an algorithm, write the program, build and run it, then check its output. Learn how decisions, loops, functions and data structures work together.
Past-paper basis: 48 written question references and 7 MCQ records found in the existing topic pages, covering 2016–2026. These counts describe the notes reviewed, not independently verified exam frequency. Source disagreements are recorded in the Question Bank.
Existing C++ tutorial: W3Schools C++
1. Topic subpages (study order)
1.1 Problem solving and language foundations
1.2 Development and translation
1.3 Program building blocks and control flow
1.4 Functions, data collections and low-level operations
2. Syllabus coverage map
Topic numbers follow the existing 15-page order. “No direct record” means none was found in the inspected page; it does not mean the topic has never been examined.
| Topic | Page | Written references in this page |
|---|---|---|
| II.1 | II.1 Basic Programming Elements and Concepts | 2018 Q3(c) · 1 mark; 2018 Q3(d) · 2 marks; 2024 Q4(b) · 6 marks; 2025 Q4(b) · 6 marks |
| II.2 | II.2 Problem Solving & Program Design | No direct written-question record; retain as a foundation |
| II.3 | II.3 Systematic Approach to Defining a Problem | No direct written-question record; retain as a foundation |
| II.4 | II.4 Components of a Programming Language | No direct written-question record; retain as a foundation |
| II.5 | II.5 Types of Programming Languages (2017) | 2017 Q3(a) · 8 marks |
| II.6 | II.6 Program Development and Execution | 2018 Q2(d) · 3 marks; 2021 Q3(c) · 5 marks; 2021 Q4(c) · 6 marks |
| II.7 | II.7 Source to Exe File Conversion Process (2016) | 2016 Q7(a) · 5 marks |
| II.8 | II.8 Program Structure & Data Types | 2019 Q3(c) · 5 marks |
| II.9 | II.9 Global, Local and Shared Variables (2017) | 2017 Q8(a) · 5 marks |
| II.10 | II.10 Standard I/O and Statements | No direct written-question record; retain as a foundation |
| II.11 | II.11 Control Structures | 2016 Q2(a) · 6 marks; 2018 Q3(a) · 5 marks; 2018 Q3(b) · 2 marks; 2018 Q3(e) · 5 marks; 2019 Q3(a) · 10 marks; 2020 Q2(a) · 8 marks; 2020 Q2(b) · 7 marks; 2020 Q4(c) · 4 marks; 2021 Q3(b) · 5 marks; 2021 Q3(d) · 4 marks; 2022 Q2(a) · 8 marks; 2024 Q3(a) · 6 marks; 2024 Q3(b) · 6 marks; 2024 Q4(a) · 6 marks; 2024 Q4(c) · 8 marks; 2025 Q4(a) · 6 marks |
| II.12 | II.12 Functions & Parameter Passing | 2016 Q3(a) · 6 marks; 2017 Q3(b) · 6 marks; 2019 Q3(b) · 5 marks; 2021 Q5(b) · 6 marks; 2022 Q6(a) · 8 marks |
| II.13 | II.13 Standard Library Functions | 2024 Q5(a) · 6 marks |
| II.14 | II.14 Arrays, Pointers, and Strings | 2018 Q3(f) · 5 marks; 2018 Q5(a) · 3 marks; 2022 Q2(c) · 6 marks; 2022 Q3(c) · 6 marks; 2022 Q4(a) · 12 marks; 2023 Q3(a) · 8 marks; 2026 Q3(b) · 6 marks; 2026 Q3(c) · 8 marks |
| II.15 | II.15 Structures, Unions, and Bit Manipulation | 2016 Q4(a) · 6 marks; 2017 Q3(c) · 6 marks; 2019 Q5(b) · 5 marks and 2023 Q3(c) · 6 marks; 2022 Q4(b) · 8 marks; 2025 Q4(c) · 8 marks; 2026 Q3(a) · 6 marks |
3. How this chapter connects
- Introduction to Computing: language types and number representation underpin code, conversion programs and logical gates.
- Object Oriented Paradigm: functions, references, structs and scope prepare you for classes, methods and objects.
- Algorithms and Data Structures: loops, recursion, arrays and pointers lead to searching, sorting and linked structures.
- Compiler Construction: the source-to-executable pipeline introduces later compiler phases.
- Computer Organization: data representation and bit masks connect software to hardware.
4. Chapter memory hooks
- Problem first: inputs → outputs → constraints → algorithm → test cases.
- Build chain: preprocess → compile → assemble → link; then load and run.
- Control: sequence → selection → repetition.
- Function: prototype → definition → call; arguments in, result out.
- Variables: scope answers “where visible?”; lifetime answers “how long alive?”
- Pointer: address-of finds a location; dereference accesses the object there.
- Bits: OR sets; AND with an inverted mask clears; XOR toggles; AND tests.
5. Outline bank (question patterns)
| Pattern | Answer order | Practice records |
|---|---|---|
| Definitions and comparisons | Definition → comparison table → example → limitation | Languages 2017; value/reference 2019 and 2021; arrays 2026 |
| Build pipeline | Labelled diagram → each stage → intermediate file → executable versus running process | 2016 Q7(a) |
| Small program | Inputs and assumptions → algorithm → code → dry run → boundary case | Temperature 2016/2024; Fibonacci 2020; factors/hex 2021; matrix product 2025 |
| Output tracing | Track variable values and pointer targets statement by statement → final output | 2018 increments; 2022 pointers/bitwise OR; 2024 Java |
| Functions | Prototype → parameters → definition → call → result | Profit 2016; quadratic 2017; recursion 2022 |
| Strings and pointers | Bounds and termination → operation → test case → complexity where relevant | Replacement 2018; palindrome 2022; reversal 2026 |
| Records and masks | Data layout → operation → code/example → limitations | Person 2016; checkout 2017; complex numbers 2025; bits 2019/2023/2026 |
6. Question Bank
Use the chronological index, quick-revision points, existing worked answers and MCQ explanations. Short code fragments are labelled as solution bodies. The source-discrepancy section distinguishes conflicting dates, question numbers and assumptions.
7. 🎯 CSS Exam Perspective
7.1 Preparation priorities from the records reviewed
- Control flow and small programs: temperature/grade conversion, loops, patterns, series, logic gates and date logic.
- Arrays, pointers and strings: bounds, output tracing, palindrome, dynamic allocation and in-place reversal.
- Functions and parameters: prototypes, value/reference, recursion and mathematical functions.
- Structures and bit operations: record-based programs, masks, bitwise output and complex-number addition.
- Foundations: expressions, scope, preprocessing, languages and build stages. Retain all syllabus topics even where no direct question was found.
These are study priorities inferred from your notes, not predictions of a future paper. Cross-topic questions can appear under more than one conceptual area; do not sum topic counts as unique exam questions.
7.2 Answer frames
- 1–3 marks: answer the exact expression, output or definition; give only the necessary explanation.
- 5–6 marks: explain the method, show the required code/table, and give one meaningful example or trace.
- 8–12 marks: cover every requested part, constraints, a complete program when requested, sample output and edge cases. For debugging, map each correction to the actual supplied line.
7.3 Accuracy checklist
- Distinguish integer division from floating-point division.
- Trace prefix/postfix operations without guessing.
- Check zero, empty arrays, invalid month/choice and boundary positions.
- Match new[] with delete[]; understand aliases and object lifetimes.
- Distinguish logical from bitwise operators; use valid unsigned shifts.
- Do not treat undefined behaviour as a predictable “garbage” result.
- Check the exact paper before repeating a disputed year, question number or rate assumption.
7.4 Revision checklist and timetable connection
- Part 1: II.1–II.7 — foundations, design, language types and development pipeline (Week 3 Tuesday).
- Part 2: II.8–II.15 — types, scope, I/O, control, functions, libraries, arrays/pointers/strings and records/bits (Week 4 catch-up target; carry forward if incomplete).
- Write and trace representative programs before moving to OOP.
- Attempt the Question Bank and record errors separately from topic coverage.
8. Existing chapter practice and self-tests
The original examples below remain available. Use the Question Bank's source notes for disputed labels and its technical checks for accuracy qualifications; selected topic pages also include specific corrections.
MCQ Traps (Topic-wide)
- Compilation translates code; interpretation executes a representation of code. An implementation may combine compilation, interpretation and JIT execution.
do-whilealways executes its body at least once, unlikewhile, which checks the condition first- In a struct, each member has separate memory; in a union, all members share the same memory
- Pass by value copies the argument (original unaffected); pass by reference operates on the original variable directly
✅ Self-Test Questions (with Answers)
Q1. Distinguish compilation from interpretation, and name one language typically associated with each approach.
Answer
- Compilation: translates source into another representation, such as object code or bytecode.
- Interpretation: executes code through an interpreter; it need not read source line by line.
- C/C++: commonly compiled ahead of time; linking produces the executable.
- Python: CPython normally compiles source to bytecode and executes it in its virtual machine.
- Java/C#: commonly compile to intermediate code, with interpretation and/or JIT compilation at runtime.
- Exam caution: speed, portability and error detection depend on the implementation and program; they are not absolute properties of a language.
- Other commonly ahead-of-time compiled examples: Fortran, Rust and Go.
- Other runtime-managed examples: PHP and JavaScript; modern JavaScript engines commonly use JIT compilation.
- Hybrid (note for CSS): Java and C# compile to an intermediate bytecode/CIL, which a virtual machine (JVM/CLR) then interprets or JIT-compiles — this is why "Java is compiled and interpreted" is a favourite MCQ.
Q2. Explain the difference between pass-by-value and pass-by-reference with a short example.
Answer
- By value: copies the argument into a parameter; assigning to that parameter does not change the caller’s variable.
- By reference in C++: binds a parameter to the caller’s object; assignment through it changes that object.
- Large objects: a
const T&can avoid a copy and prevent modification through that reference. - Pointer parameter: the pointer itself is passed by value; dereferencing it can still modify the pointed-to object.
void byValue(int x) { x = 100; } // caller unchanged
void byRef(int &x) { x = 100; } // caller changed
int main() {
int a = 5;
byValue(a); // a is still 5
byRef(a); // a is now 100
}
The classic application is swap(int &a, int &b) — it only works by reference (or via pointers, which is how C simulates it: swap(int *a, int *b)).
Q3. Why does a do-while loop always execute its body at least once?
Answer
- Post-test loop:
do-whileruns the body before checking its condition. - Minimum executions: one, provided execution reaches the loop body.
- Contrast:
whileand a conventional conditionalfortest first and may execute zero times. - Remember:
do { ... } while (condition);ends with a semicolon.
int i = 10;
do { cout << i; i++; } while (i < 5); // prints 10 — body ran once
while (i < 5) { cout << i; i++; } // prints nothing — 0 iterations
This makes do-while the natural choice for menu-driven programs and input validation, where the prompt must appear at least once before the user's answer can be checked. Note also that do-while requires a semicolon after the closing while(...).
Q4. What is the key memory difference between a struct and a union?
Answer
- Struct: members occupy distinct storage and can hold values simultaneously; padding affects total size.
- Union: members share storage; size is sufficient for the largest member and required alignment.
- Active member: normally one member is active at a time. Reading an inactive member is generally not valid C++ type-punning.
- Size examples below: common implementations, not universal guarantees.
struct S { int a; char b; double c; }; // ≈ 16 bytes (4 + 1 + pad + 8)
union U { int a; char b; double c; }; // 8 bytes (size of the largest, double)
- Union use: compact variant records, usually with a tag identifying the active member.
- C++ struct/class: both support methods and constructors; struct defaults to public member access and inheritance, class to private.
Q5. What does the pointer dereference operator * do, as opposed to the address-of operator &?
Ans: They are inverse operations:
&(address-of / reference operator) — applied to a variable, it yields the memory address where that variable is stored.&aanswers "where doesalive?"*(dereference / indirection operator) — applied to a pointer, it yields the value stored at the address the pointer holds.*panswers "what is kept at the address inp?" It is also used in a declaration (int *p;) to mean "p is a pointer to int" — the same symbol with a different role, which is a standard MCQ trap.
int a = 25;
int *p = &a; // p stores the ADDRESS of a
cout << a; // 25 — the value
cout << &a; // e.g. 0x7ffd1234 — the address
cout << p; // same address
cout << *p; // 25 — dereference: value at that address
*p = 50; // writes THROUGH the pointer → a becomes 50
- For the initialized integer above: dereferencing
&aaccessesa. - Uses: dynamic storage, array traversal, passing an address and linked data structures.
- Array caveat: array-to-pointer conversion happens in many expressions, but not all (for example,
sizeofon the array itself). - Risks: invalid or dangling pointers, leaks and undefined behaviour; a crash is possible, not guaranteed.
📝 Exam Practice: Fibonacci Series (CSS-2020)
Q: Write a C/C++ program which inputs a number from a user and prints the Fibonacci series up to that number.
Solution:
#include <iostream>
using namespace std;
int main()
{
int n;
cout << "Enter a number: ";
if (!(cin >> n) || n < 0) return 1;
long long a = 0, b = 1, next; // input ceiling n is int; wider type prevents intermediate overflow
cout << "Fibonacci series up to " << n << ": ";
while (a <= n)
{
cout << a << " ";
next = a + b;
a = b;
b = next;
}
cout << endl;
return 0;
}
Sample run:
Enter a number: 20
Fibonacci series up to 20: 0 1 1 2 3 5 8 13
Key reasoning points:
- "Up to the number" means the loop stops once a term exceeds
n— hencewhile (a <= n), not a fixed count of terms - Only two variables (
a,b) track state — no array or recursion needed, since each term depends only on the previous two - Common exam trap: "up to N" (a ceiling) vs "first N terms" (a count) are different problems worded similarly — "first N terms" needs a
forloop running exactlyntimes instead - Recursive alternative (if the question specifically asks for recursion):
int fib(int n) { return (n <= 1) ? n : fib(n-1) + fib(n-2); }— correct but exponential time; the iterative version is preferred for larger inputs
(Full trace table and further detail also live on the Source to Exe File Conversion Process subpage, where this question appeared alongside the compilation pipeline diagram.)
📚 Exam Practice Index (from chat sessions)
Quick reference to every worked exam example added so far, and where the full solution lives:
| Question | Topic | Full solution location |
|---|---|---|
| Fibonacci series up to N (CSS-2020) | Loops / Algorithms | This page (above) + Source to Exe File Conversion Process |
| Optimized Fibonacci (matrix expo., fast doubling) | Algorithms / DP | Source to Exe File Conversion Process |
| Prime number check + logical error debugging | Control Structures / Debugging | Control Structures |
| Replace character at position N in a string | Arrays, Pointers, Strings | Arrays, Pointers, and Strings |
| Binary logic gate simulator (AND/OR/XOR) | Bit Manipulation | Structures, Unions, and Bit Manipulation |
| University Records System (Student/Teacher/Course, file I/O) | OOP — Classes & Objects | Classes and Objects (under P-I.III. Object Oriented Paradigm) |
| Student Registration System (Person/Teacher/Student/Course/Allocation/Registration) | OOP — Inheritance & Composition | Classes and Objects (under P-I.III. Object Oriented Paradigm) |
| Decreasing Numeric Triangle Pattern (nested loops, +ve n) | Control Structures / Loops | This page (above) |
📝 Exam Practice: Decreasing Numeric Triangle Pattern (Past Paper)
Q: Complete the code such that it prompts the user for a positive number n and displays the output (whatever the value of n is). (HINT: instead of a triangle of stars, print a triangle of increasing numbers.)
For n=4 it prints:
1 2 3 4
1 2 3
1 2
1
General shape (n rows, each row one shorter than the last, counting up from 1):
1 2 3 4 ... n
1 2 3 4 ... n-1
. . .
. . .
1 2
1
Solution:
#include <iostream>
using namespace std;
int main()
{
int n;
cout << "Enter a positive number: ";
cin >> n;
for (int i = 0; i < n; i++) // i = which row we're on (0 to n-1)
{
for (int j = 1; j <= n - i; j++) // print 1 up to (n - i)
{
cout << j << " ";
}
cout << endl;
}
return 0;
}
Sample run (n=4):
Enter a positive number: 4
1 2 3 4
1 2 3
1 2
1
Key reasoning points:
- Outer loop (
i) controls the number of rows — runs exactlyntimes, one row per value ofifrom0ton-1 - Inner loop (
j) controls what's printed on each row — it always starts at1, but its upper bound shrinks asigrows: rowiprints1through(n - i) - This is the classic star-triangle pattern (
for j: cout << "*") with the printed character swapped for the loop counterjitself — exactly what the HINT is pointing at - Common exam trap: confusing this with an increasing triangle (where each row gets longer, upper bound
= i+1) — here the rows get shorter each time, so the inner bound must decrease (n - i), not increase - Validation reminder: since the question specifies "+ve number," a robust answer should also reject
n <= 0with a prompt/error before the loops run — worth a line even if not explicitly graded
(Cross-referenced in the Exam Practice Index below, and relevant to the Control Structures subpage's loop-pattern coverage.)