Tamil Nadu HSE Second Year Computer Applications study materials
Tamil Nadu HSE Second Year Computer Applications study resources

Tamil Nadu HSE Second Year Computer Applications: Functions and Arrays

Tamil Nadu HSE Second Year Computer Applications · Work through your exam, one topic at a time.

All guide sections

Functions and Arrays

What this domain tests

This domain tests modular programming and data collections. Expect questions on function prototypes, return values, parameter passing, scope, recursion, array indexing, traversal, and searching.

Core rules

  • A function has a return type, name, parameter list, and body. A prototype declares it before use; a definition supplies the body; a call executes it.
  • void means no return value. A non-void function must return a value compatible with its declared type.
  • Pass by value copies the argument, so changes inside the function do not affect the caller's variable.
  • Local variables exist inside a block; global variables are visible across the program. Prefer locals to avoid side effects.
  • Recursion is a function calling itself. It needs a base case; otherwise it recurses until the stack overflows.
  • An array stores elements of the same type in contiguous memory. Indexing starts at 0; an array of size n has valid indices 0 to n−1.
  • Traversal uses a loop. A 2D array is accessed as a[row][column].
  • Linear search checks elements in order; binary search requires sorted data and repeatedly halves the search range.

Worked example

Find the largest value in marks[5] = {45, 72, 68, 90, 51}. Set max = marks[0] = 45. Compare marks[1] = 72 > 45, so max = 72. Compare 68 > 72: false. Compare 90 > 72: true, so max = 90. Compare 51 > 90: false. The result is 90. The loop must start at index 1 because index 0 is already the initial maximum; starting at 0 would also work but wastes one comparison.

Traps

  • Accessing a[n] in an array of size n; the last valid index is n−1.
  • Expecting pass-by-value to modify the caller's variable.
  • Omitting the base case in recursion.
  • Declaring an array with a variable size in standard C++.
  • Using binary search on unsorted data.