TN Online TestSamacheer Kalvi practice

Function: One Mark Questions, Book Back Answers and Notes

12th Standard · Computer Science · #1

Unit 1 explains what a function is in algorithmic terms: a subroutine that takes inputs and returns a result. It covers parameters and arguments, type annotation and type inference, interface versus implementation, pure and impure functions with their side effects, and recursive functions with a base condition.

Study this chapter

Asked in previous board exams

7 questions from this chapter came in 7 past public exams. Open any of them to see the answer and explanation.

  1. March 2026
    The function which cause side effects to the arguments passed are called __________.
    See answer in the solved paper →
  2. March 2025
    Which of the following is a distinct syntactic block?
    See answer in the solved paper →
  3. March 2024
    Which of the following defines what an object can do ?
    See answer in the solved paper →
  4. March 2023
    The small sections of code that are used to perform a particular task is called :
    See answer in the solved paper →
  5. May 2022
    Which of the following is a distinct Syntactic block ?
    See answer in the solved paper →
  6. Supplementary 2021
    The small sections of code that are used to perform a particular task is called :
    See answer in the solved paper →
  7. March 2020
    The function which will give exact result when same arguments are passed are called :
    See answer in the solved paper →

About Function

Medium ~60 min study

A program of any real size is built from small pieces. The textbook calls these pieces subroutines, and in most languages a subroutine is called a function. A function is a unit of code that works on its inputs (variables and expressions) and returns a concrete output. Once you write it, you can call it again and again instead of repeating the same lines.

This chapter gives you the vocabulary that the rest of the book uses. You learn the difference between a parameter and an argument, how a function's types can be written explicitly or worked out by the compiler, and why an interface (what an object does) is kept separate from its implementation (how it does it). Then it splits functions into pure and impure ones, based on whether they have side effects, and ends with recursion.

Book back questions from this unit are mostly definitions and one-line differences: parameter vs argument, interface vs implementation, pure vs impure. Learn each pair with one small example and you can answer both the MCQs and the short answers without guessing.

What you'll learn

  • Define a subroutine and explain why programs are split into functions.
  • Tell a parameter from an argument in a given function definition and call.
  • Write a function definition with explicit type annotations and explain type inference.
  • Distinguish an interface from its implementation with an example.
  • Classify a function as pure or impure by checking for side effects and repeatable results.
  • Write a recursive function with a correct base condition.

Before you start

  • Variables, expressions and basic syntax from a high-level language.
  • The idea of a mathematical function, such as f(x) = x + 1.
  • Simple program flow and blocks from C++ or Python in Class 11.

Topics covered in this chapter

Subroutines Small sections of code that do one specific job and can be called many times. They are the basic building blocks of a program and are called functions in most languages.
Parameters and Arguments Parameters are the variables named in a function definition. Arguments are the values actually passed to them when the function is called.
Type Annotation and Inference Either the compiler infers parameter types by itself, or you annotate them as in (a: int). Parentheses are mandatory around an annotated parameter.
Interface The set of actions an object can do: the functions it offers and their signatures, with no detail of how they are carried out.
Implementation The code that actually carries out the actions defined in the interface. It can change without affecting code that only uses the interface.
Pure Functions Same arguments always give the same result and nothing outside the function changes. strlen() is the textbook example, and the compiler can avoid repeated calls.
Impure Functions Functions that can return different results for the same arguments or that change outside variables. random() and functions with side effects fall here.

Function explained

Functions, Parameters and Recursion

Subroutines and Functions

Subroutines are the basic building blocks of a program. Each one is a small section of code that does one job and can be used repeatedly. In programming languages these subroutines are called functions. A function takes input values, works on them through a fixed set of steps and gives back a result. Breaking a big program into functions makes the code shorter, easier to read and easier to fix.

Parameters and Arguments

Parameters are the variables written in the function definition. Arguments are the actual values passed to those variables when the function is called. In the textbook's let rec gcd a b, the names a and b are parameters; in the call gcd 12 18, 12 and 18 are arguments.

Types can be handled in two ways. Without annotation, the compiler infers the types using an algorithm (type inference). With annotation, you write the types yourself, as in the textbook's let rec pow (a: int) (b: int) : int. When you annotate a parameter, the parentheses around it are mandatory. Writing the types explicitly also helps you understand the error message when a type mismatch occurs.

Interface and Implementation

An interface is the set of actions an object can do. It lists the functions and what they accept and return, but not how they work. The implementation is the code that actually carries out those actions. The textbook's example is a car: the pedal is the interface, and the engine and fuel system that respond to it are the implementation. Because users depend only on the interface, the implementation can change without breaking the code that uses it.

Pure and Impure Functions

A pure function gives the same result every time it is called with the same arguments, and it has no side effects. strlen(s) is pure: if s does not change, the length does not change, so the compiler can compute it once instead of inside every loop pass. An impure function may return different results for the same arguments or change something outside itself. random() is impure because each call gives a different value. A function that modifies a variable outside its own body has a side effect and is also impure.

Recursive Functions

A recursive function calls itself to solve a smaller version of the same problem. Every recursive function needs a base condition that stops the calls; without it the function keeps calling itself and never returns. Factorial is the standard example: \(n! = n \times (n-1)!\) with \(0! = 1\) as the base case. The textbook also uses the Chameleons of Chromeland meeting problem to show how repeated steps change a state until a stopping point is reached.

Common mistakes to avoid

  • Mixing up parameters and arguments. Parameters are the names in the definition; arguments are the values given in the call.
  • Leaving out parentheses when annotating a parameter's type. Write (a: int), not a: int, in the function definition.
  • Writing a recursive function with no base condition. The calls never stop, so always check the stopping case first.
  • Calling a function pure when it changes a global variable. If anything outside the function changes, it has a side effect and is impure.
  • Describing the interface as the code that does the work. The interface only says what can be done; the implementation is the working code.

Test yourself on these with the practice test, then check the worked reasoning in the solved MCQs.

Frequently asked questions

What is the difference between a parameter and an argument?

A parameter is the variable named in the function definition. An argument is the value you pass for it when you call the function. In gcd a b, a and b are parameters; in gcd 12 18, 12 and 18 are arguments.

Why are parentheses mandatory in type annotations?

When you give a parameter an explicit type, the name and its type must be grouped as (a: int) so the definition reads correctly. The textbook states that these parentheses are mandatory. Explicit types also make a type error message easier to understand.

What is type inference?

Type inference means the compiler works out the types of parameters and the return value by itself, using an algorithm, when you do not write them. You only add annotations when you want to state the types or understand an error.

What is the difference between interface and implementation?

The interface says what an object can do: the functions it offers and their signatures. The implementation is the code that does the work. Since other code relies only on the interface, the implementation can be changed without affecting it.

Why can a compiler optimise pure functions?

A pure function returns the same value for the same arguments and changes nothing else. So if strlen(s) is called inside a loop and s does not change, the compiler can calculate the length once and reuse it instead of calling the function on every pass.

What is a side effect?

A side effect is any change a function makes outside itself, such as modifying a global variable or an argument's contents. A function with a side effect is impure, and its behaviour depends on the state of the program when it runs, which makes bugs harder to trace.

How do you stop a recursive function from running forever?

Give it a base condition: a check that returns a value directly without calling the function again. For factorial, the base case is 0! = 1. Every other call must move closer to that case, so the calls eventually end.

Last updated 15 September 2026

More chapters in Computer Science

View all
2 Data Abstraction 3 Scoping 4 Algorithmic Strategies 5 Python Variables and Operators 6 Control Structures 7 Python Functions 8 Strings and String Manipulation 9 Lists, Tuples, Sets and Dictionary 10 Python Classes and Objects 11 Database Concepts 12 Structured Query Language (SQL) 13 Python and CSV Files 14 Importing C++ Programs in Python 15 Data Manipulation through SQL 16 Data Visualization using Pyplot: Line Chart, Pie Chart and Bar Chart