Maharashtra HSC Computer Science (Bifocal) study materials
Maharashtra HSC Computer Science (Bifocal) study resources

Maharashtra HSC Computer Science (Bifocal): Programming and Problem Solving (C/C++ Constructs)

Maharashtra HSC Computer Science (Bifocal) · Work through your exam, one topic at a time.

All guide sections

Programming and Problem Solving (C/C++ Constructs)

What is tested

Programming and Problem Solving tests your ability to read C/C++ code, trace control flow, choose operators and write functions. The exam favours short programs: loops, conditionals, switch, arrays, function calls and parameter passing.

Core rules

  • A C++ program needs a main function; statements end with semicolons. #include brings in library declarations.
  • Arithmetic follows precedence: * / % before + -; use parentheses to control order. Integer division truncates toward zero.
  • if/else chooses between blocks; switch compares an integral expression with case labels and needs break to stop fall-through.
  • for, while and do-while repeat; do-while tests after the body, so it runs at least once.
  • Functions have a return type, name, parameter list and body. A prototype declares the interface before use; arguments are passed by value unless references/pointers are used.

Worked example

Trace int s=0; for(int i=1;i<=4;i++){ s += i*i; }. Iterations: i=1 adds 1, s=1; i=2 adds 4, s=5; i=3 adds 9, s=14; i=4 adds 16, s=30; i becomes 5 and the test fails. Output is 30. The loop body runs four times because the condition is checked before each iteration.

Traps

A semicolon after for(...) or if(...) creates an empty controlled statement. = assigns; == compares. Uninitialised local variables give indeterminate values. Array indices start at 0, so an array of size n uses indices 0 to n-1.