Get the most accurate TN Board Solutions for Class 12 Computer Science Chapter 01 Function here. Updated for the 2026-27 academic session, these solutions are based on the latest TN Board textbooks for Class 12 Computer Science. Our expert-created answers for Class 12 Computer Science are available for free download in PDF format.
Detailed Chapter 01 Function TN Board Solutions for Class 12 Computer Science
For Class 12 students, solving TN Board textbook questions is the most effective way to build a strong conceptual foundation. Our Class 12 Computer Science solutions follow a detailed, step-by-step approach to ensure you understand the logic behind every answer. Practicing these Chapter 01 Function solutions will improve your exam performance.
Class 12 Computer Science Chapter 01 Function TN Board Solutions PDF
12th Computer Science Guide Function Text Book Questions And Answers
I. Choose The Best Answer (I Marks)
Question 1. The small sections of code that are used to perform a particular task is called
(a) Subroutines
(b) Files
(c) Pseudo code
(d) Modules
Answer: (a) Subroutines
In simple words: Subroutines are like mini-programs within a larger program, each doing a specific job. They help organize code and avoid repeating the same instructions.
๐ฏ Exam Tip: Remember that subroutines are fundamental building blocks for modular and efficient programming, allowing code reuse and easier debugging.
Question 2. Which of the following is a unit of code that is often defined within a greater code structure?
(a) Subroutines
(b) Function
(c) Files
(d) Modules
Answer: (b) Function
In simple words: A function is a block of code designed to do one specific job within a larger program. It helps keep the code organized and reusable.
๐ฏ Exam Tip: Understand that while subroutines are a general concept, 'function' is a specific term in many programming languages for these code units, especially when they return a value.
Question 3. Which of the following is a distinct syntactic block?
(a) Subroutines
(b) Function
(c) Definition
(d) Modules
Answer: (c) Definition
In simple words: A definition in programming refers to a self-contained part of code, like a function or a variable, that is clearly separate from other parts. It helps the computer understand what each part is and how it works.
๐ฏ Exam Tip: Distinguish between a 'function' (the callable unit) and its 'definition' (the syntactic block where it's declared and described).
Question 4. The variables in a function definition are called as
(a) Subroutines
(b) Function
(c) Definition
(d) Parameters
Answer: (d) Parameters
In simple words: Parameters are like placeholders for values that a function needs to do its job. You give these values to the function when you use it.
๐ฏ Exam Tip: Remember the distinction: parameters are variables in the function's definition, while arguments are the actual values passed to those parameters when the function is called.
Question 5. The values which are passed to a function definition are called
(a) Arguments
(b) Subroutines
(c) Function
(d) Definition
Answer: (a) Arguments
In simple words: Arguments are the actual pieces of information or values you send to a function when you tell it to run. They fill the roles of the parameters.
๐ฏ Exam Tip: Grasping the difference between 'parameters' (in the definition) and 'arguments' (passed during the call) is crucial for understanding function execution.
Question 6. Which of the following are mandatory to write the type annotations in the function definition
(a) Curly braces
(b) Parentheses
(c) Square brackets
(d) Indentations
Answer: (b) Parentheses
In simple words: Parentheses are the round brackets used to show the type of data a function expects. They are a must-have for type annotations.
๐ฏ Exam Tip: Type annotations improve code readability and help with early error detection, especially in languages that support optional static typing.
Question 7. Which of the following defines what an object can do?
(a) Operating System
(b) Compiler
(c) Interface
(d) Interpreter
Answer: (c) Interface
In simple words: An interface describes what an object is capable of doing, like a list of actions it can perform, without showing how it actually does them. It's like a user manual for the object.
๐ฏ Exam Tip: Interfaces are key to polymorphism and abstraction in object-oriented programming, allowing different objects to be treated in a uniform way.
Question 8. Which of the following carries out the instructions defined in the interface?
(a) Operating System
(b) Compiler
(c) Implementation
(d) Interpreter
Answer: (c) Implementation
In simple words: Implementation is the actual code that makes the actions defined in an interface happen. It's the "how" an object performs its tasks.
๐ฏ Exam Tip: Implementation is the concrete realization of an interface, providing the specific logic for each defined action.
Question 9. The functions which will give exact result when same arguments are passed are called
(a) Impure functions
(b) Partial Functions
(c) Dynamic Functions
(d) Pure functions
Answer: (d) Pure functions
In simple words: Pure functions always give the same output if you give them the same input, and they don't change anything outside themselves. They are very predictable.
๐ฏ Exam Tip: Pure functions are valuable for testing, debugging, and parallel processing because their behavior is entirely predictable and isolated.
Question 10. The functions which cause side effects to the arguments passed are called
(a) Impure functions
(b) Partial Functions
(c) Dynamic Functions
(d) Pure functions
Answer: (a) Impure functions
In simple words: Impure functions can change things outside of themselves or give different results even with the same input. This means their outcome is not always predictable.
๐ฏ Exam Tip: While sometimes necessary, impure functions can make code harder to reason about and debug due to their potential for external impact.
II. Answer The Following Questions (2 Marks)
Question 1. What is a subroutine?
Answer: Subroutines are basic building blocks of computer programs. They are small sections of code designed to perform a particular task, which can be reused multiple times. In many programming languages, these subroutines are often called functions. These modular units help improve code organization and maintainability.
In simple words: A subroutine is a small piece of code that does a specific job, and you can use it many times in a program. In programming, they are often called functions.
๐ฏ Exam Tip: Emphasize reusability and modularity when defining subroutines, as these are their primary benefits in programming.
Question 2. Define Function with respect to the Programming language.
Answer:
- A function is a self-contained unit of code that is typically defined within a larger program structure. It performs a specific task.
- Functions can process various types of inputs, such as variables or expressions, and consistently produce a single, well-defined output. They are essential for breaking down complex problems into smaller, manageable parts.
๐ฏ Exam Tip: Highlight that functions abstract away complexity, making code easier to read, write, and manage. Always specify that they produce a 'concrete output'.
Question 3. Write the inference you get from X:=(78).
Answer: The inference from `X:=(78)` is that the value 78 is assigned or "bound" to the name `X`. This means `X` now refers to the integer 78. This is a common way to initialize a variable with a specific value.
In simple words: From `X:=(78)`, we learn that the number 78 is now stored under the name `X`.
๐ฏ Exam Tip: Clearly state that `:=` is an assignment operator, which links a name (variable) to a value.
Question 4. Differentiate Interface and Implementation
Answer: Interface and implementation are two distinct but related concepts in programming.
| Interface | Implementation |
|---|---|
| Interface defines what an object can do, but won't actually do it. | Implementation carries out the instructions defined in the interface. |
In simple words: An interface tells us what an object *can do*, like a list of actions. The implementation is the actual code that *makes those actions happen*.
๐ฏ Exam Tip: Remember that the interface is about "what" and the implementation is about "how", a key principle in object-oriented design.
Question 5. Which of the following is a normal function definition and which is a recursive function definition?
(I) Let Recursive sum x y: return x + y
(II) let disp: print 'welcome'
(III) let Recursive sum num: if (num! = 0) then return num + sum (num โ 1) else return num
Answer:
1. Recursive function: (III) let Recursive sum num: if (num! = 0) then return num + sum (num - 1) else return num
2. Normal function: (I) Let Recursive sum x y: return x + y
3. Normal function: (II) let disp: print 'welcome'
A recursive function is one that calls itself as part of its definition, while a normal function does not. The `sum (num - 1)` part in (III) shows it calls itself.
In simple words: A normal function just does its job. A recursive function is special because it calls itself to keep working until it reaches an end point.
๐ฏ Exam Tip: The defining characteristic of a recursive function is its self-reference, which must always include a base case to prevent infinite loops.
III. Answer The Following Questions (3 Marks)
Question 1. Mention the characteristics of Interface.
Answer: The characteristics of an interface are:
- A class template defines the interfaces to allow an object to be created and managed correctly. This ensures consistent behavior across objects.
- An object's attributes (what it is) and behavior (what it does) are managed by sending specific functions to that object. This allows for clear interaction with the object.
๐ฏ Exam Tip: Remember that interfaces promote clear contracts between components, which is vital for building complex, maintainable software systems.
Question 2. Why strlen() is called pure function?
Answer: The `strlen()` function is generally considered a pure function because it consistently calculates the length of a string without causing any changes to the string itself or anything else outside its scope. Even though `strlen()` iterates over the string 's' to find its length, it only reads from external memory (the string 's') but does not modify it. The value it returns (the string length) depends solely on its input argument 's'. If the compiler can recognize this, it might optimize calls to `strlen()` within a loop, if 's' is not modified, making the loop execute more efficiently. Its output is always the same for the same input, and it produces no side effects.
In simple words: `strlen()` is pure because it always gives the same answer for the same text, and it doesn't change the text or anything else in the program.
๐ฏ Exam Tip: Focus on the two key aspects of pure functions: same input always yields same output, and no side effects (no changes to external state).
Question 3. What is the side effect of impure function? Give example.
Answer: An impure function has "side effects" when it interacts with the outside world in ways that can be observed or cause changes beyond its return value. These side effects make the function's behavior less predictable. Some common side effects include:
- Modifying variables outside the function's scope, including its arguments if they are passed by reference.
- Depending on or changing global variables or external data.
- Performing input/output operations like reading from a file, writing to a console, or making network requests.
- Calling other impure functions that have side effects.
When a function relies on variables or other functions defined outside its own block, its behavior cannot be guaranteed to be the same every time it is called. For instance, the mathematical function `random()` is an example of an impure function because it generates different outputs each time it is called, even with no explicit input. This unpredictability comes from its interaction with an internal state or system-level random number generator.
For example: let random number
let a:= random()
if a> 10 then
return: a
else
return 10
Here, the function `random()` is impure because we can't be sure what result it will give when called. Its outcome is not solely determined by its input.
In simple words: An impure function can change things outside itself or give different answers even with the same input. For example, a "random number" function is impure because it gives a new number every time you use it.
๐ฏ Exam Tip: When discussing impure functions, highlight how their interaction with external state (like global variables, I/O, or a system clock) leads to unpredictability and makes code harder to test.
Question 4. Differentiate pure and impure functions.
Answer: Pure and impure functions differ primarily in their predictability and interaction with the program's state.
| Pure Function | Impure Function |
|---|---|
| 1 The return value of pure functions depends solely on its arguments passed. | 1 The return value of impure functions does not solely depend on its arguments passed. |
| 2 Pure functions with the same set of arguments always return same values. | 2 Impure functions with the same set of arguments may return different values. |
| 3 They do not have any side effects. | 3 They have side effects. |
| 4 They do not modify the arguments which are passed to them. | 4 They may modify the arguments which are passed to them. |
| 5 Example: `strlen()`, `sqrt()` | 5 Example: `random()`, `date()` |
In simple words: Pure functions always give the same answer for the same input and don't change anything else. Impure functions can give different answers or change things outside themselves.
๐ฏ Exam Tip: When comparing, always emphasize the lack of side effects and determinism for pure functions versus the presence of side effects and potential for non-determinism for impure functions.
Question 5. What happens if you modify a variable outside the function? Give an example
Answer: If you modify a variable that exists outside a function's own definition block, the function's behavior becomes unpredictable. This is because the function's output will no longer depend solely on its own inputs, but also on the external state of that variable. This makes the function impure, and you can never be sure that the function will behave the same way every time it is called, even with the same arguments. It introduces a "side effect" which is hard to track and debug.
For example, consider this code snippet:
`let y := 0`
`(int) inc (int) x`
`y := y + x;`
`return (y)`
In this example, the value of `y` (an external variable) is changed inside the `inc()` function. As `y` is modified by each call, the function's return value will change each time, even if `x` is the same. The side effect of the `inc()` function is that it changes the value of the externally visible variable `y`. This makes the function `inc()` impure.
In simple words: If a function changes a variable that is outside of it, the function becomes unpredictable. Its answer might change every time you use it, even with the same input, because it's changing something external.
๐ฏ Exam Tip: Explain that modifying external variables within a function is a classic example of a side effect, leading to impure functions and making code harder to manage.
IV. Answer The Following Questions (5 Marks)
Question 1. What are called Parameters and Write a note on
1. Parameter Without Type
2. Parameter With Type
Answer:
Parameter: Parameters are the variables defined in a function's definition that act as placeholders for the values the function expects to receive when called.
Arguments: Arguments are the actual values or expressions that are passed to a function when it is invoked, which correspond to its parameters.
Parameters can be passed in two main ways:
1. Parameter without Type:
In some programming contexts, you might define functions without explicitly stating the data types of their parameters. The language often infers the types automatically.
Example of a function definition:
`(requires: b >= 0)`
`(returns: a to the power of b)`
`let rec pow a b:=`
`if b=0 then 1`
`else a pow a*(b-1)`
In this example, 'b' is the parameter, and the value passed to 'b' is the argument. The `(requires)` part specifies a precondition (b must be non-negative), and `(returns)` specifies the postcondition (the result will be 'a' raised to the power of 'b'). No specific data types are mentioned for 'a' or 'b'. Many languages solve this type inference problem automatically.
- In the above function definition, the variable 'b' is the parameter, and the value passed to 'b' is the argument.
- The precondition (requirements) and postcondition (returns) for the function are given.
- Here, we have not mentioned any specific data types for the parameters.
- Some programming languages can automatically figure out the data types, but sometimes you need to state the type explicitly.
2. Parameter with Type:
When you explicitly state the data types for parameters in a function definition, it is called parameter with type. This improves code clarity and helps the compiler catch errors early.
Now let us write the same function definition with types for some reason:
`(requires: b > 0)`
`(returns: a to the power of b)`
`let rec pow (a: int) (b: int): int :=`
`if b=0 then 1 else a * pow b (a-1)`
- When you specify type annotations for 'a' and 'b', using parentheses around the parameter and its type is required.
- There are situations where you need to write down the types explicitly, especially for clarity.
- This is useful when the compiler gives type errors that are not immediately clear, helping to debug the code.
In simple words: Parameters are the names used for values inside a function's rules. Arguments are the actual values you give to the function. "Parameter without Type" means the computer guesses the type of value. "Parameter with Type" means you clearly tell the computer what type of value to expect.
๐ฏ Exam Tip: Clearly differentiate between "parameter" (placeholder in definition) and "argument" (actual value passed). Emphasize that explicit typing (Parameter with Type) enhances code safety and readability.
Question 2. Identify in the following program
`let rec gcd a b :=`
`if b < > 0 then gcd b (a mod b) else return a`
(I) Name of the function
(II) Identify the statement which tells it is a recursive function
(III) Name of the argument variable
(IV) Statement which invokes the function recursively
(V) Statement which terminates the recursion
Answer:
(I) Name of the function: `gcd`
(II) Identify the statement which tells it is a recursive function: `let rec`
(III) Name of the argument variable: `a, b`
(IV) Statement which invokes the function recursively: `gcd b (a mod b) [when b < > 0]`
(V) Statement which terminates the recursion: `return a (when b becomes 0)`
This program calculates the greatest common divisor using a recursive approach, where the function calls itself until a base condition is met. The `let rec` keyword specifically indicates that `gcd` is a recursive function.
In simple words: The function's name is `gcd`. The `let rec` part tells us it's a recursive function. The inputs are `a` and `b`. The function calls itself using `gcd b (a mod b)`. It stops when `b` becomes 0, and then it gives `a` as the answer.
๐ฏ Exam Tip: For recursive functions, always identify the `rec` keyword (if present), the recursive call itself, and most importantly, the base case that stops the recursion.
Question 3. Explain with example Pure and impure functions.
Answer:
Pure functions:
Pure functions are those that always produce the exact same result for the same set of input arguments, and they do not cause any observable side effects outside their scope. This means they do not modify any external state or global variables. For example, the mathematical function `sin(0)` will always return 0. Similarly, a function that squares a number will always return the same result for the same input, like `square(5)` will always return 25. These functions are predictable and easy to test because their behavior is isolated.
Let us see an example:
`let square x`
`return: x * x`
The `square` function is pure because it consistently returns `x * x` for a given `x` and does not affect anything else in the program.
Impure functions:
Impure functions, in contrast, can produce different results even with the same input arguments, or they might cause side effects, meaning they interact with or change the program's state outside their own scope. This makes their behavior less predictable.
- When variables inside the function cause side effects through other functions that are not passed as arguments, the function is considered impure.
- If a function depends on variables or other functions defined outside its own block, its behavior can change unpredictably with each call.
For example, the mathematical function `random()` will give different outputs every time it is called. This is because it relies on an internal or external state that changes.
Let's consider another example:
`let Random number`
`let a := random()`
`if a > 10 then`
`return: a`
`else`
`return: 10`
Here, the `Random` function is impure because its output is not fixed; we cannot be sure what the result will be when we call it. Impure functions can make debugging harder because their effects can be widespread and difficult to trace.
In simple words: Pure functions always give the same answer for the same inputs and don't change anything else. For example, `square(5)` always gives `25`. Impure functions can give different answers or change things outside themselves. For example, a `random()` function always gives a new, different number.
๐ฏ Exam Tip: Provide clear, simple examples for both types. Emphasize that predictability and absence of side effects are hallmarks of pure functions, while their opposites characterize impure functions.
Question 4. Explain with example interface and implementation
Answer:
Interface Vs Implementation:
An **interface** is essentially a blueprint or a set of actions that an object can perform. It defines what an object can do, but it does not specify how those actions are carried out. In Object-Oriented Programming (OOP), an interface describes all the functions (methods) that a class must have if it wants to be considered a certain type. For instance, when you press a light switch, you know the light will turn on or off, but you don't necessarily care about the complex wiring behind it.
The **implementation** is the actual code that executes the instructions defined in the interface. It specifies *how* an object performs the actions outlined in its interface.
Consider a real-world example: anything that "ACTS LIKE" a light should have functions like `turnOn()` and `turnOff()`. The purpose of interfaces in programming is to ensure that any class identified as a "Light" type must include these specific functions (e.g., `X`, `Y`, `Z`). This allows the computer to enforce consistent behavior.
A class declaration combines its external interface (what it can do, its visible state) with its implementation (the code that performs the behavior). An object is a specific instance created from this class. The interface effectively defines an object's visibility to the outside world, controlling how other parts of the program can interact with it.
Characteristics of interface:
- The class template specifies the interfaces to enable an object to be created and operated properly.
- An object's attributes and behavior are controlled by sending functions to the object.
| Interface | Implementation |
|---|---|
| Interface defines what an object can do, but won't actually do it. | Implementation carries out the instructions defined in the interface. |
Example: Car Accelerator
- The person driving a car doesn't need to know the car's internal mechanics.
- To increase speed, the driver simply presses the accelerator to achieve the desired behavior.
- The accelerator acts as the interface between the driver (the calling object) and the engine (the called object).
- In this scenario, `Speed(70)` is an interface function.
- Internally, the car's engine handles all the complex tasks: mixing fuel, air, managing pressure, and using electricity to propel the vehicle.
All these actions are separated from the driver, who just wants the car to go faster. This distinction clearly shows how an interface is separated from its underlying implementation, allowing for simpler interaction with complex systems.
In simple words: An interface shows what an object can do (like pressing a car accelerator). The implementation is the hidden working code that makes it happen (like the engine actually speeding up the car). The driver uses the interface, not worrying about the complex implementation.
๐ฏ Exam Tip: Use a real-world analogy like a car's dashboard (interface) and engine (implementation) to clearly illustrate the separation of concerns.
12th Computer Science Guide Function Additional Questions And Answers
I. Choose The Best Answer (1 Mark)
Question 1. ______ are expressed using statements of a programming language.
(a) Algorithm
(b) Procedure
(c) Specification
(d) Abstraction
Answer: (a) Algorithm
In simple words: An algorithm is a step-by-step plan for solving a problem, and these steps are written using programming language statements.
๐ฏ Exam Tip: Remember that an algorithm is the logical blueprint, while programming language statements are the tools used to express that blueprint for a computer.
Question 3. A function definition which calls itself is called
(a) user-defined function
(b) recursive function
(c) built-in function
(d) derived function
Answer: (b) recursive function
In simple words: When a function uses itself inside its own code to solve a problem, it's called a recursive function. This helps solve complex problems by breaking them into smaller, similar parts.
๐ฏ Exam Tip: Remember that recursive functions must always have a base case to stop the recursion, preventing infinite loops.
Question 4. Find the correct statement from the following.
(a) a := (24) has an expression
(b) (24) is an expression
Answer: (a) a := (24) has an expression
In simple words: The statement means that the variable 'a' is assigned the value '24'. Here, '24' itself is an expression, and the assignment 'a := 24' is a statement containing that expression.
๐ฏ Exam Tip: Understand the difference between an expression (which evaluates to a value) and a statement (which performs an action).
Question 5. strlen() is an example of function.
(a) pure
(b) impure
(c) user-defined
(d) recursive
Answer: (a) pure
In simple words: The `strlen()` function always gives the same answer for the same input string and does not change anything outside of itself. This makes it a pure function, which is predictable and easy to test.
๐ฏ Exam Tip: Pure functions are key for predictable code because they don't have side effects and always produce the same output for the same input.
Question 6. Evaluation of functions does not cause any side effects to its output?
(a) Impure
(b) built-in
(c) Recursive
(d) pure
Answer: (d) pure
In simple words: Pure functions do not change anything outside their scope or depend on anything external to their input, always giving the same result for the same input without unexpected changes. This makes them very reliable for calculations.
๐ฏ Exam Tip: Pure functions are important in functional programming because they make code easier to understand, test, and debug.
Question 7. The name of the function in let rec pow ab := is
(a) Let
(b) Rec
(c) Pow
(d) a b
Answer: (c) Pow
In simple words: In the given code, `pow` is the part that names the function. `let rec` tells the computer it's a recursive function, and `ab` are the inputs.
๐ฏ Exam Tip: In functional programming, the function name usually comes right after keywords like `let` or `let rec`.
Question 8. An is an instance created from the class.
(a) Interface
(b) object
(c) member
(d) function
Answer: (b) object
In simple words: A class is like a blueprint for creating things, and an object is a real item made from that blueprint. For example, 'Car' is a class, and 'myRedCar' is an object of that class.
๐ฏ Exam Tip: Remember that a class defines properties and behaviors, while an object is a specific entity that has those properties and behaviors.
Question 9. In object-oriented programs are the interface.
(a) classes
(b) object
(c) function
(d) implementation
Answer: (a) classes
In simple words: In object-oriented programming, classes act like blueprints that define what an object can do, which essentially describes its interface. They specify the structure and behavior for all objects created from them.
๐ฏ Exam Tip: An interface in OOP provides a way to interact with an object without knowing its internal details, promoting abstraction and modularity.
Question 10. In b = 0, = is operator
(a) Assignment
(b) Equality
(c) Logical
(d) Not equal
Answer: (b) Equality
In simple words: In many programming languages, a single equals sign (`=`) is used to give a value to a variable, which is called assignment. A double equals sign (`==`) checks if two values are the same, which is called equality.
๐ฏ Exam Tip: Always double-check whether you need to assign a value (`=`) or compare two values (`==`) to avoid common programming errors.
II. Answer the following questions (2 and 3 Marks)
Question 1. What are the two types of parameter passing?
Answer: The two types of parameter passing are:
1. Parameter without type: Here, the data type of the parameter is not specified explicitly.
2. Parameter with type: In this case, the data type of the parameter is clearly mentioned.
In simple words: Parameters can be passed either by just giving their names, or by giving their names along with what type of data they are.
๐ฏ Exam Tip: Clearly understanding parameter types helps prevent errors and makes your code more robust.
Question 2. What is meant by Definition?
Answer: In programming, definitions refer to distinct syntactic blocks. These blocks specify how a particular function, variable, or concept is introduced and structured within the code. For example, a function definition outlines the function's name, parameters, and the code it executes.
In simple words: A definition is a special part of code that tells the computer exactly what something is, like a function or a variable, and how it works.
๐ฏ Exam Tip: Always ensure your definitions are clear and follow the language's syntax rules to avoid errors.
Question 3. Write the syntax for the function definitions?
Answer: The general syntax for function definitions in some functional programming languages is:
`let rec fn a1 a2 ... an := k`
Where:
`fn`: Represents the function's name.
`a1 ... an`: These are variables used as parameters for the function.
`rec`: This keyword is included if the function is recursive, meaning it calls itself. It can be omitted for non-recursive functions.
This structure helps define how a function takes inputs and produces an output.
In simple words: To create a function, you write `let rec` (if it calls itself), then the function's name, followed by its input names, then `:=` and the code it runs.
๐ฏ Exam Tip: Remember to use the `rec` keyword only when defining a recursive function; otherwise, it is not needed.
Question 4. Define Argument.
Answer: Arguments are the actual values that are passed to a function when it is called or executed. These values correspond to the parameters defined in the function's definition, providing the specific data the function needs to perform its task. For instance, in `add(5, 3)`, `5` and `3` are the arguments.
In simple words: Arguments are the actual pieces of information or values you give to a function when you use it.
๐ฏ Exam Tip: Distinguish between parameters (placeholders in a function definition) and arguments (actual values passed during a function call).
Question 5. Write notes on Interface.
Answer:
โข An interface defines a set of actions or capabilities that an object can perform. It specifies "what" an object can do, without describing "how" it does it.
โข In programming, an interface acts like a contract, outlining the methods that a class must implement. This helps in creating standardized ways to interact with different objects. For example, a `Printable` interface might require a `print()` method.
In simple words: An interface shows what an object can do, like a button on a remote control, but it doesn't show how it does it. It's like a list of tasks an object promises to perform.
๐ฏ Exam Tip: Interfaces are crucial for achieving abstraction and polymorphism in object-oriented programming, allowing different classes to be treated uniformly.
Question 6. Define Implementation.
Answer: Implementation refers to the actual code that carries out the instructions defined by an interface. While an interface describes "what" an object can do, the implementation details "how" those actions are performed. It involves writing the specific logic and steps for each method specified in an interface or class definition. This is where the actual work happens behind the scenes.
In simple words: Implementation is the actual code that makes an object do the things its interface says it can do. It's the "how-to" part.
๐ฏ Exam Tip: Understanding implementation helps you see how abstract definitions are turned into working code, which is vital for building functional software.
Question 7. Write notes on Pure functions.
Answer:
โข Pure functions are functions that consistently produce the same output for the same set of inputs and do not cause any side effects. This means they don't change any external state or variables outside their own scope.
โข For example, a mathematical function like `sin(0)` will always return `0`. Another example is `strlen()`, which always returns the length of a given string without altering the string itself. Pure functions are easy to test and predict because of their consistent behavior.
In simple words: Pure functions always give the exact same answer if you give them the same input, and they don't change anything else in your program. Think of them like a simple math calculation.
๐ฏ Exam Tip: Pure functions are valuable in programming for their predictability and ease of testing, which helps in writing more reliable code.
Question 8. Write notes on the Impure function.
Answer:
โข Impure functions are those that can produce different outputs for the same inputs or cause side effects, meaning they interact with or change things outside their own scope. This can include modifying global variables, performing I/O operations, or depending on external factors.
โข For instance, a `random()` function is impure because it returns a different number each time it's called, even with no input. Similarly, a function that writes to a file or changes a user interface element would be considered impure because it affects the external state.
In simple words: Impure functions might give different answers even with the same input, or they might change things outside themselves, like showing a message or saving a file.
๐ฏ Exam Tip: Be cautious with impure functions, as their unpredictable nature can make debugging more challenging; use them thoughtfully.
Question 9. What is a Recursive function?
Answer: A recursive function is a function that calls itself in its own definition. This technique is used to solve problems that can be broken down into smaller, similar sub-problems. Each time the function calls itself, it works on a simpler version of the original problem until it reaches a basic case (the "base case") that can be solved directly, stopping the recursion. A common example is calculating factorials.
In simple words: A recursive function is one that solves a problem by calling itself over and over with simpler versions of the problem, until it reaches a very basic case it can solve easily.
๐ฏ Exam Tip: Always ensure a recursive function has a clear base case to avoid infinite recursion and program crashes.
Question 10. Differentiate parameters and arguments.
Answer:
| Parameters | Arguments |
|---|---|
| Parameters are the variables in a function definition. | Arguments are the values which are passed to a function definition. |
In simple words: Parameters are the names given to inputs when you write a function, like "number 1" and "number 2". Arguments are the actual numbers you put in when you use that function, like "5" and "10".
๐ฏ Exam Tip: Remember: parameters are defined in the function signature, while arguments are supplied during the function call.
Question 11. Give function definition for the Chameleons of Chromeland problem?
Answer: The function definition for the Chameleons of Chromeland problem can be given as:
`let rec monochromatize abc :=`
`if a > 0 then`
`a, b, c := a - 1, b - 1, c + 2`
`else`
`a := 0, b := 0, c := a + b + c`
`return c`
This code describes how the number of chameleons of different colors (a, b, c) changes when two chameleons of different colors meet, aiming to make all chameleons one color. The `rec` keyword here indicates that this is a recursive function, which means it calls itself to solve smaller parts of the problem until a base condition is met.
In simple words: This code is a function that describes how chameleons change colors. If there are chameleons of different colors, they meet and change into a new set of colors. If not, it means all are the same color, and the function calculates the total count.
๐ฏ Exam Tip: Pay close attention to the base case (`else` block) and the recursive step (`if` block) to ensure the logic handles all scenarios correctly.
Question 12. Define Object:
Answer: In object-oriented programming, an object is a distinct instance created from a class. It combines both data (attributes or properties) and the actions that can be performed on that data (methods or behaviors) into a single unit. Objects are real-world entities like a car, a student, or a bank account, represented in a program. They allow for modular and reusable code.
In simple words: An object is like a real-world thing inside your computer program, made from a blueprint called a class. It has its own features and can do certain actions.
๐ฏ Exam Tip: Remember that a class is a blueprint, while an object is a specific, tangible creation based on that blueprint.
III. Answer the following questions (5 Marks)
Question 1. Explain the syntax of function definitions
Answer: The syntax for defining functions in many functional programming languages is quite similar to mathematical notation. It usually involves:
โข The `let` keyword: This introduces a definition. If the function is recursive (calls itself), the `rec` keyword is added after `let`.
โข Function Name: This is the identifier given to the function, for example, `fn`.
โข Arguments/Parameters: These are the inputs the function takes, listed after the function name, such as `a1 a2 ... an`.
โข The assignment operator (`:=` or `=`) is used to separate the function header from its body.
โข Function Body: This is the formula or expression that calculates the function's result, often denoted by `k`.
So, a typical definition looks like: `let rec fn a1 a2 ... an := k`. This clear structure helps the compiler understand how to execute the function and what to expect as a result. For instance, in `let add x y = x + y`, `add` is the function name, `x` and `y` are parameters, and `x + y` is the body.
In simple words: A function definition starts with `let` (and `rec` if it calls itself), then its name, its inputs, and finally the code that tells it what to do to get an answer.
๐ฏ Exam Tip: Always remember that the `rec` keyword is only for functions that call themselves; omitting it for non-recursive functions is good practice.
Question 2. Write a short note and syntax for function types?
Answer: Function types describe the inputs and outputs of a function, much like a blueprint for its data flow. This helps ensure that functions are used correctly and that data types are consistent throughout the program.
The basic syntax for function types is often shown with arrows:
โข `x โ y`: This represents a function that takes one input of type `x` and returns one output of type `y`.
โข `x1 โ x2 โ y`: This means a function takes an input of type `x1`, then an input of type `x2`, and finally returns an output of type `y`. This is often seen in languages with currying, where a function can take arguments one by one.
โข `x1 โ ... โ xn โ y`: This is a more general form, indicating a function that accepts `n` arguments of types `x1` through `xn` and produces an output of type `y`.
These type annotations are important for compilers to check for type errors and can also help programmers understand how different parts of their code fit together. They make the code more readable and prevent many common mistakes before the program even runs.
In simple words: Function types tell us what kind of information a function takes in and what kind of information it gives back. We use arrows to show this, like `input type โ output type`. This helps make sure the right kind of data is used.
๐ฏ Exam Tip: Type annotations improve code readability and help catch type-related errors early, which is especially beneficial in large projects.
Question 3. On the island, there are different types of chameleons. Whenever two different color chameleons meet they both change their colors to the third color. Suppose two types of chameleons are equal in number. Construct an algorithm that arranges meetings between these two types so that they change their color to the third type. In the end, all should display the same color.
Answer: Let's assume there are three colors of chameleons: Red (R), Green (G), and Blue (B). When two different colors meet, they both change to the third color. For example, if a Red and a Green chameleon meet, both turn Blue. If the numbers of two types of chameleons are equal, we can use a recursive function to simulate meetings until all chameleons are the same color. A possible algorithm is:
`let rec monochromatize a b c :=`
`if a > 0 then`
`a, b, c := a - 1, b - 1, c + 2`
`else`
`a := 0, b := 0, c := a + b + c`
`return c`
This function models the process: if there are chameleons of color `a` (assuming `a` and `b` are the two equal, non-zero types), one `a` and one `b` meet. They both vanish from their original colors (`a-1`, `b-1`) and two new chameleons of color `c` appear (`c+2`). This continues until one of the initial colors (`a` or `b`) reaches zero, then the base case ensures the calculation. The goal is to reach a state where two counts are zero and one count has the total number of chameleons. This demonstrates a common pattern in recursive problem-solving, where the problem size is reduced with each call.
In simple words: This code creates a plan for chameleons to change colors until they are all the same. If two different color chameleons meet, they both become the third color. This keeps happening until only one color is left, and the function returns the final count of that color.
๐ฏ Exam Tip: When dealing with recursive solutions, ensure the recursive step moves towards the base case and that the base case correctly terminates the recursion.
HANDS-ON PRACTICE
Question 1. Write the algorithmic function definition to find the minimum among 3 numbers.
Answer: The algorithmic function definition to find the minimum among three numbers `a`, `b`, and `c` can be written using nested conditional statements:
`let min 3abc :=`
`if a < b then`
`if a < c then a else c`
`else`
`if b < c then b else c`
This function first compares `a` with `b`. If `a` is smaller, it then compares `a` with `c` to find the overall minimum. If `b` was smaller than `a`, it then compares `b` with `c` to determine the minimum. This step-by-step comparison ensures the smallest of the three numbers is correctly identified. Such conditional logic is fundamental in programming for decision-making.
In simple words: This function finds the smallest number among three. It first checks if the first number is smaller than the second. Then it checks against the third number to find the very smallest one.
๐ฏ Exam Tip: When using nested `if-else` statements, ensure each condition logically leads to the correct comparison, covering all possibilities.
Question 2. Write the algorithmic recursive function definition to find the sum of natural numbers.
Answer: The algorithmic recursive function definition to find the sum of natural numbers up to a given number `num` is:
`let rec sum num:`
`If(num!=0)`
`then return num+sum(num-1)`
`else return num`
This function works by breaking down the problem: the sum of numbers up to `num` is `num` plus the sum of numbers up to `num-1`. The `if (num!=0)` part handles the recursive step. The `else return num` is the base case, which means when `num` becomes 0, the recursion stops and the sum is calculated. For example, `sum(3)` would be `3 + sum(2)`, which is `3 + (2 + sum(1))`, which is `3 + (2 + (1 + sum(0)))`, finally evaluating to `3 + 2 + 1 + 0 = 6`.
In simple words: This function adds up all the natural numbers from 1 to a given number. It does this by adding the current number to the sum of all numbers before it, until it reaches zero.
๐ฏ Exam Tip: For recursive sum functions, the base case `return 0` (or `return num` when `num` is 0) is vital to stop the recursion and provide the final result.
Free study material for Computer Science
TN Board Solutions Class 12 Computer Science Chapter 01 Function
Students can now access the TN Board Solutions for Chapter 01 Function prepared by teachers on our website. These solutions cover all questions in exercise in your Class 12 Computer Science textbook. Each answer is updated based on the current academic session as per the latest TN Board syllabus.
Detailed Explanations for Chapter 01 Function
Our expert teachers have provided step-by-step explanations for all the difficult questions in the Class 12 Computer Science chapter. Along with the final answers, we have also explained the concept behind it to help you build stronger understanding of each topic. This will be really helpful for Class 12 students who want to understand both theoretical and practical questions. By studying these TN Board Questions and Answers your basic concepts will improve a lot.
Benefits of using Computer Science Class 12 Solved Papers
Using our Computer Science solutions regularly students will be able to improve their logical thinking and problem-solving speed. These Class 12 solutions are a guide for self-study and homework assistance. Along with the chapter-wise solutions, you should also refer to our Revision Notes and Sample Papers for Chapter 01 Function to get a complete preparation experience.
FAQs
The complete and updated Samacheer Kalvi Class 12 Computer Science Solutions Chapter 1 Function is available for free on StudiesToday.com. These solutions for Class 12 Computer Science are as per latest TN Board curriculum.
Yes, our experts have revised the Samacheer Kalvi Class 12 Computer Science Solutions Chapter 1 Function as per 2026 exam pattern. All textbook exercises have been solved and have added explanation about how the Computer Science concepts are applied in case-study and assertion-reasoning questions.
Toppers recommend using TN Board language because TN Board marking schemes are strictly based on textbook definitions. Our Samacheer Kalvi Class 12 Computer Science Solutions Chapter 1 Function will help students to get full marks in the theory paper.
Yes, we provide bilingual support for Class 12 Computer Science. You can access Samacheer Kalvi Class 12 Computer Science Solutions Chapter 1 Function in both English and Hindi medium.
Yes, you can download the entire Samacheer Kalvi Class 12 Computer Science Solutions Chapter 1 Function in printable PDF format for offline study on any device.