12th Standard Syllabus & Materials
12th Standard
TN 12th Computer Applications மின்னணு தரவு பரிமாற்றம் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications மின் - வணிக பாதுகாப்பு அமைப்புகள் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications மின்னணு செலுத்தல் முறைகள் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications மின் - வணிகம் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications திறந்த மூல கருத்துருக்கள் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications வலையமைப்பு வடமிடல் Sample Question Papers Study Material - QB365 Set A

Published on: 06/01/2020
Function
Download Tamil Nadu 12th Standard Computer Science question papers, model tests, one-mark questions, important questions, and public exam papers in PDF format. Free study materials and answer keys for TN State Board students.
Questions + Answers key
Take MCQ Computer Science Test

1.
The recursive function is defined using the keyword
let
let rec
name
infer
2.
The function definition is introduced by the keyword
def
rec
let
infer
3.
Which of the following carries out the instructions defined in the interface?
Operating System
Compiler
Implementation
Interpreter
4.
Which of the following are mandatory to write the type annotations in the function definition?
{ }
( )
[ ]
< >
5.
Which of the following is a unit of code that is often defined within a greater code structure?
Subroutines
Function
Files
Modules
6.
Give an example of impure function.
7.
Give an example of function definition parameter with type.
8.
Give an example of function definition parameter without type.
9.
Write the inference you get from X : = (78).
10.
What is a subroutine?
11.
Write a short note an syntax for function types.
12.
Explain the syntax of function definitions.
13.
Wha happens if you modify a variable outside the function? Give an example.
14.
What is the side effect of impure function. Give example.
15.
Why strlen is called pure function?
16.
Explain with an example interface and implementation.
17.
Explain with example Pure and impure functions.
18.
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 invoke the function recursively
v) Statement which terminates the recursion
19.
What are called Parameters and write a note on
(i) Parameter without Type
(ii) Parameter with Type
1.
(b)
let rec
2.
(c)
let
3.
(c)
Implementation
4.
(b)
( )
5.
(b)
Function
6.
let y: = 0
(int) inc (int) x
y: =y+x;
return (y)
7.
(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 )
8.
(requires: b>=0 )
(returns: a to the power of b)
let rec pow a b:=
if b=0 then I
else a * pow a (b-1)
9.
X: = (78) has an expression in it but (78) is not itself an expression. Rather, it is a function definition. Definitions bind values to names, in this case the value 78 being bound to the name 'X'.
10.
(i) Subroutines are the basic building blocks of computer programs. Subroutines are small sections of code that are used to perform a particular task that can be used repeatedly.
(ii) In Programming languages these subroutines are called as Functions.
11.
The syntax for function types
x\(\rightarrow \)y
x1 \(\rightarrow \)x2\(\rightarrow \)y
x1 \(\rightarrow \) .... \(\rightarrow \)x n\(\rightarrow \)y
The 'x' and 'y' are variables indicating types. The type x \(\rightarrow \) y is the type of a function that gets an input of type 'x' and returns an output of type 'y'. Where as x1\(\rightarrow \) x2 -\(\rightarrow \) y is a type of a function that takes two inputs, the first input is of type 'x1' and the second input of type 'x1', and returns an output of type 'y'. Likewise x1 \(\rightarrow \)...\(\rightarrow \)x n\(\rightarrow \)y has type 'x' as input of n arguments and 'y' type as output.
12.
(i) The syntax to define functions is close to the mathematical usage: the definition is introduced by the keyword let, followed by the name of the function and its arguments; then the formula that computes the image of the argument is written after an = sign. If you want to define a recursive function: use "let rec" instead of "let".
(ii) Syntax: The syntax for function definitions:
let rec fn a1 a2 ... an :;= k
(iii) Here the 'fn' is a variable indicating an identifier being used as a function name. The names 'a1' to 'an' are variables indicating the identifiers used as parameters. The keyword 'rec' is required if 'fn' is to be a recursive function; otherwise it may be omitted.
13.
The most popular groups of side effects is modifying the variable outside of function.
For example:
let y: = 0
(int) inc (int) x
y: =y+x;
return (y)
In the above example the value of y get changed inside the function definition due to which the result will change each time.
14.
The variables used inside the function may cause side effects though the functions which are not passed with any arguments. In such cases the function is called impure function.
For example the mathematical function random() will give different outputs for the same function call.
let randomnumber :=
a := random()
if a > 10 then
return: a
else
return: 10
15.
(i) Strlen is a pure function because the function takes one variable as a parameter, and accesses it to find its length.
(ii) This function reads external memory but does not change it, and the value returned derives from the external memory accessed.
16.
Interface:
(i) An interface is a set of action that an object can do. For example when you press a light switch, the light goes on, you may not have cared how it splashed the light. In Object Oriented Programnming language, an Interface is a description of all functions.
(ii) In our example, anything that "ACTS LIKE" a light, should have function definitions like turn_on () and a turn_off (). The purpose of interfaces is to allow the Computer to enforce the properties of the class.
Implementation:
(i) Implementation carries out the instructions defined in the interface.
(ii) How the object is processed and executed is the implementation.
(iii) A class declaration combines the external interface (its local state) with an implementation of that interface (the code that carries out the behaviour).
For example, let's take the example of increasing a car's speed.

(iv) The person who drives the car doesn't care about the internal working. To increase the speed of the car he just presses the accelerator to get the desired behaviour. Here the accelerator is the interface between the driver (the calling / invoking object) and the engine ( the called object).
(v) In this case, the function call would be speed (70):, this is the interface Internally, the engine of the car is doing all the things but fuel, air, pressure, and electricity come together to create the power to move the vehicle.
(vi) All of these actions are separated from the driver, who just wants to go faster. Thus we separate interface from implementation.
17.
Pure functions:
(i) Pure functions are functions which will give exact result when the same arguments are passed.
(ii) For example the mathematical function sin (0) always results 0. This means that every time you call the function with the same arguments, you wil always get the same result.
(iii) A function can be a pure function provided it should not have any external variable which will alter the behavior of that variable.
let us see an Example:
Let square x : =
return: x * x
(iv) The above function square is a pure function because it will not give different results for same input.
(v) There are various theoretical advantages of having pure functions. One advantage is that if a function is pure, then if it is called several times with the same arguments, the compiler only needs to actually call the function once.
Example:
let length s:=
i:= 0
let i:= 0;
if i<strlen (s) then
-- Do something which doesn't affect s
++1
(vi) If it is compiled, strlen (s) is called each time and strlen needs to iterate over the whole of 's'. If the compiler is smart enough to work out that strlen is a pure function and that 's' is not updated in the loop, then it can remove the redundant extra calls to strlen and make the loop to execute only one time.
(vii) From these what we can understand, strlen is a pure function because the function takes one variable as a parameter, and accesses it to find its length. This function reads external memory but does not change it, and the value returned derives from the external memory accessed
Impure functions:
(i) The variables used inside the function may cause side effects through the functions which are not passed with any arguments. In which cases the function is called impure function.
(ii) When a function depends on variable or functions outside of its definition block, you can never be sure that the function will behave the same every time it's called. For example, the mathematical functions random ( ) will give different outputs for the same function call.
Example:
let randomnumber:=
a := random()
if a > 10 then
return: a
else
return: 10
(iii) Here the function Random is impure as it is not sure what will be the result when we call the function
18.
(i) gcd
(ii) let rec gcd
(iii) a, b
(iv) gcd(a mod b)
(v) return a
19.
Parameters and arguments:
Parameters are the variable in a function definition and arguments are the values which are passed to a function definition
(i) Parameter without Type: Let us see an 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*powa(b-1)
(i) In the above function definition variable 'b' is the parameter and the value which is passed to the variable 'b' is the argument. The precondition (requires) and postcondition (returns) of the function is given.
(ii) Note we have not mentioned any types (data types). Some language computer solves this type (data type) inference problem algorithmically, but some require the type to be mentioned.
(iii) In, the above function deinition if expression can return 1 in the then branch, shows that as per the typing rule the entire if expression has type int
(iv) Since the if expression is of type 'int', the function's return type also be int. 'b' is compared to 0 with the equality operator. so 'b' is also a type of int: Since 'a' is multiplied with another expression using the operator, 'a' must be an int.
(ii) Parameter with Type: Now let us write the same function definition with types for some reasons:
(requires: b > 0 )
(returns: a to the power of b )
let rec pow (a:int) (b:int): int :=
if b=0 then 1
n else a * pow b (a-1)
(i) When we write the type annotations for ‘a’ and ‘b’ the parentheses are mandatory. Generally, we can leave out these annotations, because it's simpler to let the compiler infer them.
(ii) There are times we may want to explicitly write down types. This is useful on times when you get a type error from the compiler that doesn't make sense. Explicitly annotating the types can help with debugging such an error message.
(iii) The syntax to define functions is close to the mathematical usage: the definition is introduced by the keyword let followed by the name of the function and its arguments; then the formula that computes the image of the argumentis written atter an := sign. If you want to define a recursive function: use "let rec" instead of "let"
Syntax:The syntax for function detinitions: let irec fn al a2 ... an := k
(iv) Here the 'fn' is used as a function name. The nanmes 'a1' to 'an'are variables used as parameters. The keyword 'rec' is required if 'fn' is to be a recursive function; otherwise it may be omitted.
12th Standard Syllabus & Materials
12th Standard
TN 12th Computer Applications களப்பெயர் முறைமை (DNS) Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications வலையமைப்பு எடுத்துக்காட்டுகள் மற்றும் நெறிமுறைகள் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications கணினி வலையமைப்பு ஓர் அறிமுகம் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications PHP-உடன் MySQL-ஐ இணைத்தல் Sample Question Papers Study Material - QB365 Set A
Tamilnadu Stateboard 12th Standard Subjects

Maths

Chemistry

Physics

Biology

Computer Science

Business Maths and Statistics

Economics

Commerce

Accountancy

History

Computer Applications

Biology

Computer Technology

Computer Applications

Computer Science

Business Maths and Statistics

Commerce

Economics

Maths

Chemistry

Physics

Computer Technology

History

Accountancy

Tamil

English

French
Tamilnadu Stateboard Standards