TN State Board 11th Computer Science Important Questions Chapter 11 Functions

Question 1.
Write the types of functions in C++.
Answer:
Functions can be classified into two types,

  1. Pre-defined or Built-in or Library Functions.
  2. User-defined Function.

Question 2.
What is getchar( ) and putchar ( ) function.
Answer:
The predefined function getchar( ) is used to get a single character from keyboard and putchar() function is used to display it.

Question 3.
Differentiate between getchar( ) and gets( ) function.
Answer:

getchar( )

 gets( )

It is used to get single Character from keyboard.  It reads a string from standard input and stores it into the string pointed by the variable.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 4.
What is puts( ) function?
Answer:
puts( ) function prints the string read by gets( ) function in a newline.

Question 5.
Name the character functions in C++.
Answer:

  1. isalnum( )
  2. isalpha( )
  3. isdigit( )
  4. islower( )
  5. isupper( )
  6. toupper( )
  7. tolower( )

Question 6.
Write the syntax for toupper( ) and its uses.
Answer:
toupper( ) is used to convert the given character into its uppercase.
It will return the upper case equivalent of the given character. If the given character itself is in upper case, the output will be the same.
Syntax:
char toupper(char c);
The following statement will assign the character constant ‘K’ to the variable c.
char c = toupper(‘k’);
But, the output of the statement given below will be‘B’itself.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 7.
How will you define a function? Write the syntax.
Answer:
A function must be defined before it is used anywhere in the program. The general syntax of a function definition is:
Return_Data_Type Function_ name(parameter list)
{
Body of the function
}

Question 8.
What do you mean by void data type? Give example.
Answer:
void data type indicates the compiler that the function does not return a value or in a larger context void indicates that it holds nothing.
Eg:
void fun(void)
> The above function prototype tells compiler that the function fun( ) neither receives values from calling program nor return a value to the calling program.

Question 9.
Write the methods of calling function.
Answer:
In C++, the arguments can be passed to a function in two ways. The function calling methods can be classified based on the method of passing arguments as based on the method of passing the arguments. The function calling methods can be classified as

  1. Call by Value method,
  2. Call by Reference or Address method.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 10.
What are the advantages of inline functions.
Answer:
The advantages of inline functions:

  1. Inline functions execute faster but requires more memory space.
  2. Reduce the complexity of using STACKS.

Question 11.
Write the return type for the following function prototype.
Answer:

Function Prototype

 Return type

int sum(int, float)  int
float area(float, float)  float
char result( )  char
double factfint( )  double

Question 12.
What is recursion?
Answer:
A function that calls itself is known as recursive function. This technique is known as recursion.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 13.
Write the types of scopes in C++.
Answer:
Scope refers to the accessibility of a variable. There are four types of scopes in C++. They are: Local scope, Function scope, File scope and Class scope.

Question 14.
How will you reveal the hidden scope of a variable?
Answer:
The scope operator reveals the hidden scope of a variable. The scope resolution operator (::) is used to access a Global variable when there is a Local variable with same name.

Question 15.
Give the reason to need for functions in C++.
Answer:
To reduce size and complexity of the program functions are used. The programmers can make use of sub programs either writing their own functions or calling them from standard library.
Divide and Conquer

  1. Complicated programs can be. divided into manageable sub programs called functions.
  2. A programmer can focus on developing, debugging and testing individual functions.
  3. Many programmers can work on different functions simultaneously.

Reusability:

  1. Few lines of code may be repeatedly used in different contexts. Duplicationof the same code can be eliminated by using functions which improves the maintenance and reduce program size.
  2. Some functions can be called multiple times with different inputs.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 16.
Write the standard input/output function in C++.
Answer:
The header file stido.h defines the standard I/O predefined functions getchar( ), putchar( ), gets( ), puts( ) and etc.,
The predefined function getchar( ) is used to get a single character from keyboard and putchar( ) function is used to display it.
C++ code to accept a character and displays it:
#include
#include
using namespace std;
int main( )
{
cout<<“\n Type a Character :”;
char ch = getchar();
cout<<“\n The entered Character is:”;
putchar(ch);
return 0;
}
Output:
Type a Character : T
The entered Character is: T
gets( ) function reads a string from standard input and stores it into the string pointed by the variable. puts() function prints the string read by gets() function in a newline.
C++ code to accepts and display a string:
#include
#include
using namespace std; .
int main( )
{
char str[50];
cout<<“Enter a string :”;
gets(str);
cout<<“You entered:”
puts(str);
return (0) ;
}
Output:
Enter a string : Computer Science
You entered: Computer Science

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 17.
What is the use of sqrt( ) function?
Answer:
The sqrt( ) function returns the square root of the given value of the argument. It takes a single non-negative argument. If a, negative value is passed as an argument to sqrt( ) function, a domain error occurs.
.#include
#include using namespace std;
int main( )
{ .
double x = 625, result;
result = sqrt(x);
cout<<“sqrt (“<<x<<“) =”<<result;
return 0;
}
Output:
sqrt(625) = 25

Question 18.
Write short notes on constant Arguments.
Answer:
The constant variable can be declared using const keyword. The const keyword makes variable value stable. The constant variable should be initialized while declaring. The const modifier enables to assign an initial value to a variable that cannot be changed later inside the body of the function.
Syntax:

(const )
Eg:
(i) int minimumfconst int a=10);
(ii) float area(const float pi=3.14, int r=5);

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 19.
Write short note on inline functions.
Answer:
An inline function looks like normal function in the source file but inserts the function’s code directly into the calling program. To make a function inline, kgyword inline is inserted in the function header.
Syntax:
inline returntype
functionname(datatype parameternamel, … datatype parameternameN)

Advantages of inline functions:
(i) Inline functions execute faster but requires more memory space.
(ii) Reduce the complexity of using STACKS.

Question 20.
What is return statement? Write the syntax. Give example.
Answer:
The return statement is used to return from a function. It is categorized as a jump statement because it terminates the execution of the function and transfer the control to the called statement. A return may or may not have a value associated with it. If return has a value associated with it, that value becomes the return value for the calling statement. Even for void function return statement without parameter can be used to terminate the function.
Syntax:
return expression/variable;
Example:
return (a+b);
return(a);
return; // to terminate the function

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 21.
Write a program to find the factorial of a Number using Recursion.
Answer:
#include
using namespace std;
int factorial(int); // Function prototype //
int main( )
{
int no;
cout<<“\nEnter a number to find its factorial:”; cin>>no;
cout<<“\nFactorial of Number” <<no<<“=”< 1)
{
return m*factorial(m-1);
}
else
{
return 1;
}
}
Output:
Enter a number to find its factorial: 5
Factorial of Number 5 = 120

Question 22.
Explain the different types of character function in C++.
Answer:
The header file defines various operations on characters. Following are the various character functions available in C++. The header file ctype.h is to be included to use these functions in a program.
isalnum( )
It is used to check whether a character is alphanumeric or not. This function returns non-zero value if c is a digit or a letter, else it returns 0.
Syntax:
int isalnum (char c)
Eg:
int r = isalnum(‘5’);
cout< But the statements given below assign 0 to the variable n, since the given character is neither an alphabet nor a digit,
char c = ‘$’
int n = isalnum (c);
cout<<c; .
Output:
0
isalpha( )
The isalpha( ) function is used to check whether the given character is an alphabet or not.
Syntax:
int isalpha(char c);
It will return 1 if the given character is an alphabet, and 0 otherwise 0. The following statement assigns 0 to the variable n, since the given character is not an alphabet,
int n = isalpha(‘3’);
The statement given below displays 1, since the given character is an alphabet.
cout< isdigit( )
It is used to check whether a given character is a digit or not. This function will return 1 if the given character is a digit, and 0 otherwise.

Syntax:
int isdigit(char c);
When the following program is executed, the value of the variable n will be 1,since the given character is not a digit.
islower( )
It is used to check whether a character is in lower case (small letter) or not. This functions will return a non-zero value, if the given character is a lower case alphabet and 0 otherwise.
Syntax:
int islower(char c);
After executing the following statements, the value of the variable n will be 1 since the given character is in lower case.
char ch = ‘n’ ;
int n = islower(ch);
The statement given below will assign 0 to the variable n, since the given character is an uppercase alphabet.
int n = islower(‘P’);
isupper( )
It is used to check the given character is uppercase. This function will return 1 if true otherwise 0. For the following examples value 1 will be assigned to n and 0 for m.
int n=isupper(‘A’);
int m=isupper(‘a’);
toupper( )
It is used to convert the given character into its uppercase. This function will return the upper case equivalent of the given character. If the given character itself is in upper case, the output will be the same.

Syntax:
char toupper(char c) ;
The following statement will assign the character constant ‘K’ to the variable c.
char c = toupper(‘k’);
The output of the statement given below will be ‘B’ itself.
cout< tolower( )
It is used to convert the given character into its lowercase. This function will return the lower case equivalent of the given character. If the given character itself is in lower case, the output will be the same.

Syntax:
char tolower(char c);
The following statement will assign the character constant ‘k’ to the variable c.
char c = tolower(‘K’);
The output of the statement given below will be ‘b’ itself. ,
cout<

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 23.
Explain the various string manipulation in C++.
Answer:
The library string.h (also referred as cstring) has several common functions for dealing with strings stored in arrays of characters. The string.h header file is t& be included before using any string function.
strcpy( )
The strcpy( ) function takes two arguments: target and source. It copies the character string pointed by the source to the memory location pointed by the target. The null terminating character (\0) is also copied.

strlen( )
The strlen( ) takes a null terminated byte string source as its argument and returns its length. The length does not include the null(\0) character.

strcmp( )
The strcmp( ) function takes two arguments: string 1 and string2. It compares the contents of string 1 and string2 lexicographically.

The strcmp( ) function returns a:
(i) Positive value if the first differing character in string 1 is greater than the corresponding character in string2. (ASCII values are compared)
(ii) Negative value if the first differing character in string 1 is less than the corresponding character in string2.
(iii) 0 if string 1 and string2 are equal.

strcat( )
The strcat( ) function takes two arguments: target and source. This function appends copy of the character string pointed by the source to the end of string pointed by the target.

strupr ()
The strupr( ) function is used to convert the given string into Uppercase letters.

strlwr( )
The strlwr( ) function is used to convert the given string into Lowercase letters.

Question 24.
Explain the basic mathematical functions in C++.
Answer:
The mathematical functions are defined in math.h header file which includes basic mathematical functions.

cos( ) function
The cos( ) function takes a single argument in radians. The cos() function returns the value in the range of [- 1,1]. The returned value is either in double, float or long double.

sqrt( ) function
The sqrt( ) function returns the square root of the given value of the argument. The sqrt( ) function takes a single non-negative argument. If a negative value is passed as an argument to sqrt( ) function, a domain error occurs.

sin( ) function
The sin( ) function takes a single argument in radians. The sin( ) function returns the value in the range of [-1, 1]. The returned value is either in double, float or long double.

pow( ) function
The pow( ) function returns base raised to the power of exponent. If any argument passed to pow( ) is long double, the return type is promoted to long double. If not, the return type is double. The pow( ) function takes two arguments:
(i) base – the base value
(ii) exponent – exponent of the base.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 25.
Explain call by reference or address method with example.
Answer:
Call by reference, copies the address of the actual argument into the formal parameter. Since the address of the argument is passed, any change made in the formal parameter will be reflected back in the actual parameter.
#include
using namespace std;
void display(int &x) //passing address of a//
{
x=x*x;
cout<<“\n\nThe Value inside display function (n1 x n1)
: “< }
int main( )
{
int n1;
cout<<“\nEnter the Value for N1:”; cin>>n1;
cout<<“\nThe Value of N1 is inside main function Before passing:”<<n1; .
display(n1);
cout<<“\nThe Value of N1 is inside main function After passing (n1 × n1) :”<< n1;
return(0);
}
Output:
Enter the Value for N1 :45
The Value of N1 is inside main function Before passing : 45
The Value inside display function (n1 × n1) : 2025
The Value of N1 is inside main function After passing (n1 × n1) : 2025

Question 26.
Explain the different forms of user-defined function declaration with example.
Answer:
A Function without return value and without parameter:

The following program is an example for a function with no return and no arguments
passed.

The name of the function is display( ), its return data type is void and it does not have any argument.
#include
using namespace std;,
void display( )
{
cout<<“First C++ Program with
Function”;
}
int main( )
{
display( ); // Function calling statement//
return (0);
Output:
First C++ Program with Function
A Function with return value and without parameter:
The name of the function is display( ), its return type is int and it does not have any argument. The return statement returns a value to the calling function and transfers the program control back to the calling statement.
#include
using namespace std;
int display( )
{
int a,b,s;
cout<<“Enter 2 numbers:”; cin>>a>>b;
s=a+b;
return s;
}
int main ( )
{
int m=display( );
cout<<“\nThe Sum=”<<m; return(0);
}
Output:
Enter 2 numbers: 10 30
The Sum=40.
A Function without return value and with parameter:
The name of the function is display( ), its return type is void and it has two parameters or arguments x and y to receive two values.
The return statement returns the control back to the calling statement.
#include
using namespace std;
void display(int x,int y)
{
int s=x+y;
cout<<“The Sum of Passed Values:”<<s;
}
int main( )
{
int a,b;
cout<<“\nEnter the First Number:”; cin>>a;
cout<<“\nEnter the Second Number:”; cin>>b;
display(a,b);
return (0);
}
Output:
Enter the First Number :50
Enter the Second Number :45
The Sum of Passed Values: 95
A Function with return value and with parameter:
The name of the function is display( ), its return type is int and it has two parameters or arguments x and y to receive two values. The return statement returns the control back to the calling statement.
#include
using namespace std;
int display(int x, int y)
{
int s=x+y;
return s;
}
int main( )
{
int a,b;
cout<<“\nEnter the First Number:”; cin>>a;
cout<<“\nEnter the Second Number:”; cin>>b;
int s=display(a,b);
cout<<“\nExample: Function with
Return Value and with Arguments”;
cout<<“\nThe Sum of Passed Values :”<<s;
return (0);
}
Output:
Enter the First Number :45
Enter the Second Number :67
Example: Function with Return Value and with Arguments
The Sum of Passed Values: 112

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Write C++ program to solve the following problems:

Question 27.
Program that reads two strings and appends the first string to the second.
Answer:
For example, if the first string is entered as Tamil and second string as nadu, the program should print Tamilnadu. Use string library header.
#include
#include
using namespace std;
int main ( )
{
char stringl[50]= “Tamil”;
char string2[50]= “nadu”;
strcat(stringl, string2);
cout<<stringl;
return 0;
}
Output:
Tamilnadu

Question 28.
Program that reads a string and converts it to uppercase. Include required header files.
Answer:
#include
#include
#include
using namespace; std;
int main( )
{
char str1[50];
cout<<“\nType any string in lower case:”;
gets(strl);
cout<<“\n Converted the Source string”<<str1< return 0;
}
Output:
Type any string in lower case : computer science
Converted the Source string Computer science into upper Case is COMPUTER SCIENCE

Question 29.
Program that checks whether a given character is an alphabet or not. If it is an alphabet, whether it is lowercase character or uppercase character? Include required, header files.
Answer:
#include
#include
using namespace std;
int main( )
{
char c;
cout<<“Enter a character”; cin>>n;
if((c>=’a’&&c<=’z’)\\ (c>=”A”&&c<=’z’))
{
if(isupper (c) )
cout<<“The given character is in uppercase”;
else
cout<<“The given character is in lowercase”;
}
else
{
eout<<“The given character is
}
return 0;.
}
Output:
Enter a character: B
The given character is in uppercase.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 30.
Program that checks whether the given character is alphanumeric or a digit. Add appropriate header file.
Answer:
#include
#include
#include
using namespace std;
int main( )
{
char ch;
int r;
cout<<“\n Type a Character:”;
ch = getchar( );
r = isalnum(ch);
cout<<“\nThe Return Value of isalnum(ch) is :”<<r;
}
Output-1:
Type a Character :A
The Return Value of isalnum(ch) is :1
Output-2:
Type a Character 😕
The Return Value of isalnum(ch) is : 0

Question 31.
Write a function called zero_small ( ) that has two integer arguments being passed by reference and sets smaller of the two numbers to 0. Write the main program to access this function.
Answer:
#include
using namespace std;
void zero-small(int &, int&)
int main( )
{
int x,y;
cout<<“Enter first number:”; cin>>x;
cout<<“Enter second number:”; cin>>y;
zero-small(x, y);
cout<<“first number is:”<<x;
cout<<”\n second number is:”<<y;
return 0;
}
void zero-small(int&a, int&b)
if(a<b)
a=0;
else
b=0;
}

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 32.
Write definition for a function sumseries ( ) in C++ with two arguments/ parameters – double x and int n. The function should return a value of type double and it should perform sum of the following series:
x-x2 /3! + x3 / 5! – x4 / 7! + x5 / 9! -… upto n terms.
Answer:
#include
#include
#include using namespace std;
double sumseries(int xl, int nl);
int main( )
(
int x;
int n;
cout<<“Enter the value of X and N”; , cin>>x>>n.;
cout<<“\nThe sum of the series = ” < return 0;
}
double sumseries(int x1, int n1)
{
double sum=0;
int c=0
for(int i=1; i<=(2*n1); i=i+2)
{
int f=1;
for(int j=1; j<=i; j++)
{
f=f*j;
}
c=c+1;
if (c%2==1)
{
sum=sum+pow(x1,c)/f;
}
else
{
sum=sum-pow(x1, c) / f
}
}
return sum;
}

Question 33.
Program that invokes a function calc ( ) which intakes two intergers and an arithmetic operator and prints the corresponding result.
Answer:
#include
using namespace std;
int calc(int a,int b);
int main( )
{
int n1, n2, sum;
cout<<“Enter first number:”; cin>>n1;
cout<<“Enter second number:”; cin>>n2;
sum=calc(n1,n2);
cout<<“The sum of two numbers is:”<<sum<<endl;
return 0;
}
int calc (int a, int b)
{
return (a+b);
}
Output:
Enter first number: 10
Enter second number: 20
The sum of two numbers is: 30

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 34.
Define Functions.
Answer:
(i) A large program can typically be split into small sub-programs (blocks) called as functions where each sub-program can perform some specific functionality.
(ii) Functions reduce the size and complexity of a program, makes it easier to understand, test and check for errors.

Question 35.
Write about strlen( ) function.
Answer:

  1. The strlen( ) takes a null terminated byte string source as its argument and returns its length
  2. The length does not include the null(\0) character.

Question 36.
What are the importance of void data type?
Answer:
Void type has two important purposes

  1. To indicate the function dues not ret s„
  2. To declare a generic pointer.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 37.
What is Parameter and list its types?
Answer:
Arguments or parameters are the means to pass values from the calling function to the called function.

  1. The variables used in the function definition as parameters are known as formal parameters.
  2. The constants, variables or expressions used in the function call are known as actual parameters.

Question 38.
Write a note on Local Scope.
Answer:

  1. A local variable is defined within a block. A block of code begins and ends with curly braces { }.
  2. The scope of a local variable is the block in which it is defined.
  3. A local variable cannot be accessed from outside the block of its declaration.
  4. A local variable is created upon entry into its block and destroyed upon exit

Question 39.
What is Built-in functions ?
Answer:
C++ provides a rich collection of functions ready to be used for various tasks. The tasks to be performed by each of these are already written, debugged and compiled. Their definitions alone are grouped and stored in files called header files. Such ready-to- use sub programs are called pre-defined functions or built-in functions.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 40.
What is the difference between isupper( ) and toupper( ) functions?
Answer:

isupper( )

 toupper( )

It is used to check the given character is uppercase.  It is used to convert the given character into its uppercase.
It will return 1 if true otherwise 0.  It will return the Uppercase equivalent of the given character.
Eg: int n=isupper(‘A’); The value 1 will be assigned to n  Eg: char c=toupper (‘k’). The character constant ‘k’ is assigned to the variable c.

Question 41.
Write about strcmp( ) function.
Answer:
The strcmp( ) function takes two arguments: string 1 and string2. It compares the contents of string 1 and string2.
The strcmp( ) function returns:
(i) Positive value if the first differing character in string 1 is greater than the corresponding character in string2. (ASCII values are compared)
(ii) Negative value if the first differing character in string 1 is less than the corresponding character in string2.
(iii) 0 if string1 and string2 are equal.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 42.
Write short note on pow( ) function in C++.
Answer:
The pow( ) function returns base raised to the power of exponent. If any argument passed to pow( ) is long double, the return type is promoted to long double. If not, the return type is double. The pow( ) function takes two arguments:
(i) base – the base value
(ii) exponent – exponent of the base
Eg:
cout< Output: 16

Question 43.
What are the information the prototype provides to the compiler?
Answer:

TN State Board 11th Computer Science Important Questions Chapter 11 Functions 1

The prototype above provides the following information to the compiler:
(i) The return value of the function is of type long.
(ii) fact is the name of the function.
(iii) The function is called with two arguments:
(a) The first argument is of int data type.
(b) The second argument is of double data type.
Eg:
int display(int , int) // function prototype//

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 44.
What is default arguments ? Give example.
Answer:
In C++, default values can be assigned to the formal parameters of a function prototype. The Default arguments allows to omit some arguments when calling the function.
When calling a function,
(i) For any missing arguments, compiler uses the values in default arguments for the called function.
(ii) The default value is given in the form of variable initialization.
Eg: void default value (int n1=10, n2=100);
(iii) The default arguments facilitate the function call statement with partial or no arguments.
Eg: defaultvalue(x,y);
defaultvalue(200,150);
defaultvalue(150);
defaultvalue(x, 150);
(iv) The default values can be included in the function prototype from right to left, i.e., cannot have a default value for an argument in between the argument list.
Eg: void defaultvalue(int n1=10, n2);
//invalid prototype.
void defaultvalue(int n1, n2 = 10);
//valid prototype.

Question 45.
Explain Call by value method with suitable example.
Answer:
In call by value, the value of an actual parameter is copied into the formal parameter of the function. Changes made to formal parameter within the function will have no effect on the actual parameter.
#include
using namespace std;
void display(int x)
{
int a=x*x;
cout<<“\n\nThe Value inside display function (a*a):”<<a;
}
int main( )
{
int a;
cout<<“\nExample : Function call by value:”;
cout<<“\n\nEnter the Value for A:”; cin>>a; .
display(a);
cout<<“\n\nThe Value inside main function”<<a;
return (0);
}
Output:
Example : Function call by value
Enter the Value for A : 5
The Value inside display function(a*a) : 25
The Value inside main function 5

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 46.
What is Recursion? Write a program to find GCD using recursion.
Answer:
A function that calls itself is known as recursive function. And, this technique is known as recursion.
#include
using namespace std;
int gcd(int x,int y) ;
int main( )
{
int a,b;
cout<<“Enter two numbers:”; cin>>a>>b;
cout<<“\n The GCD of “<<a<<“and”<<b<<“is”< return (0);
}
int gcd(int x,int y)
{
int z=x%y;
if(z==0)
return(y);
else :
return (gcd(y,z));
}

Question 47.
What are the different forms of function return? Explain with example.
Answer:
The return statement stops execution and returns to the calling function. When a return statement is executed, the function is terminated immediately at that point.

The return statement:
It is used to return from a function. It is categorized as a jump statement because it terminates the execution of the function and transfers the control to the called statement. A return may or may not have a value associated with it.

Syntax:
return expression/variable;
Example : return(a+b); return( (a);
return; // to terminate the function

The Returning values:
The functions that return no value is declared as void. The data type of a function is treated as int, if no data type is explicitly mentioned.
Eg:
int add (int,int);
add (int,int);
In both prototypes, the return value is int, because by default the return value of a function in C++ is of type int.

Function Prototype

 Return type

int sum(int, float)  int
float area(float, float)  float
char result( )  char
double fact(int n)  double

Returning Non-integer values:A string can also be returned to a calling statement.

#include
#include
using namespace std;
char *display( )
{
return(“chennai”);
}
int main ( )
{
char s[50];
strcpy(s,display ( )) ;
cout<<“\nExample:Function with Non Integer Return”<<s;
return (0);
}
Output :
Example: Function with Non Integer Return Chennai
The Returning by reference:
#include
using namespace std;
int main( )
{
int n1=150;
int &n1ref=n1;
cout<<“\n The Value of N1 = ” <<nl<<” and nlReference =” <<nlref;
n1ref++;
co.ut<<“\nAfter. nl increased the Value of N1= “<<n1;
cout<<“and n1Reference =” <<nlref;
return (0);
}
Output:
The Value of N1 = 150 and n1Reference = 150
After n1 increased the Value of N1 = 151 and n1Reference = 151

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 48.
Explain scope of variable with example. Scope refers to the accessibility of a variable.
Answer:
Local scope, Function scope, File scope and Class scope are the four types of scopes in C++.

Local Scope:
(i) A local variable is defined within a block. A block of code begins and ends with curly braces { }.
(ii) The scope of a local variable is the block in which it is defined.
(iii) A local variable cannot be accessed from outside the block of its declaration.
(iv) A local variable is created upon entry into its block and destroyed upon exit.

Function Scope:
(i) The scope of variables declared within a function is extended to the function block and all sub-blocks therein.
(ii) The life time of a function scope variable, is the life time of the function block. The scope of formal parameters is function scope.

File Scope:
(i) A variable declared above all blocks and functions (including main ( ) ) has the scope of a file. The life time of a file scope variable is the life time of a program.
(ii) The file scope variable is also called as global variable.

Class Scope:
(i) A class is a new way of creating and implementing a user defined data type. Classes provide a method for packing data of different types together.
(ii) Data members are the data variables that represent the features or properties of a class.

class student

{

private:

intt mark1, mark2, total;

};

The class student contains mark 1, mark 2 and total are data variables. Its scope is within the class student only.

Example
#include
using namespace std;
int i=0; //file scope
void func( )
{
cout<<i; int main ( ) { int flag=1, a=100;//function scope while (flag) { int x=200;//local scope if(a>x)
{
– –
– –
}
else
{
– – –
– – – –
}
}
}

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 49.
Write a program to accept any integer number and reverse it.
Answer:
#include
using namespace std;
int main ( )
}
long int num, sum;
int digit;
cout<<“Enter an Integer Number:”; cin>>num;
if(num<0)
{
cout<<“Enter a positive Integer “<<endl; return -1; } sum=0; while (num>0)
{
digit = num%10;
sum=(sum*10)+digit;
num=num/10;
}
cout<<“Reverse number is:”<<endl;
return 0;
}
Output:
Enter an Integer Number: 15389
Reverse number is : 98351

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Choose the correct answer:

Question 1.
_________ reduce the size and complexity of a program.
(a) Functions
(b) Pointers
(c) Structures
(d) Objects
Answer:
(a) Functions

Question 2
_______ functions are default functions.
(a) Built-in
(b) User-defined ( )
(c) Add 0
(d) Multiply ( )
Answer:
(a) Built-in

Question 3.
________ functions are created by users.
(a) Void( )
(b) Main( )
(c) String( )
(d) User-defined
Answer:
(d) User-defined

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 4.
Functions can be classified into _______ types.
(a) three
(b) two
(c) five
(d) four
Answer:
(b) two

Question 5.
A header file can be identified by their file extension:
(a) .f
(b) .c
(c) .d
(d) .h
Answer:
(d) .h

Question 6
________ is used to get a single character from keyboard.
(a) putchar( )
(b) put( )
(c) getchar( )
(d) gets( )
Answer:
(c) getchar( )

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 7.
_______ displays a single character.
(a) putchar( )
(b) gets( )
(c) write( )
(d) writechar( )
Answer:
(a) putchar( )

Question 8.
_______ reads a string from standard input.
(a) input( )
(b) gets( )
(c) getchar( )
(d) getch( )
Answer:
(b) gets( )

Question 9.
_______ function used to print the string.
(a) write( )
(b) puts( )
(c) putin( )
(d) put( )
Answer:
(b) puts( )

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 10.
_____ defines various operations on characters.
(a) ctype.h
(b) chtype.h
(c) chartype.h
(d) ctype.c
Answer:
(a) ctype.h

Question 11.
What will be the output for the given statement?
char c=’$’;
int n = isalnum (c);
cout<<c;
(a) 1
(b) null
(c) 0
(d) c
Answer:
(c) 0

Question 12.
The function is used to check whether the given character is an alphabet or not.
(a) isalphabet( )
(b) isalnum( )
(c) isalpha( )
(d) isdigit( )
Answer:
(c) isalpha( )

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 13.
What is the value of n?
int n = isalpha(‘3’)
(a) 1
(b) 3
(c) n
(d) 0
Answer:
(d) 0

Question 14.
What is the value of n?
int n = isalpha(‘a’)
(a) n
(b) a
(c) 1
(d) 0
Answer:
(c) 1

Question 15.
_________ is used to check whether a given character is a digit or not.
(a) isalpha( )
(b) isnum( )
(c) isdigit( )
(d) isalnum( )
Answer:
(c) isdigit( )

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 16.
______ is used to check whether a given character is in lower case or not.
(a) islower( )
(b) lower( )
(c) loweris( )
(d) tolower( )
Answer:
(a) islower( )

Question 17.
What will be the value of n?
int n = islower(‘P’); ……….
(a) P
(b) p
(c) 1
(d) 0
Answer:
(d) 0

Question 18.
______ is used to check the given character is uppercase.
(a) upper( )
(b) isupper( )
(c) uppercase( )
(d) toupper( )
Answer:
(b) isupper( )

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 19.
int n=isupper(‘A’);
The value of n is:
(a) A
(b) a
(c) 1
(d) 0
Answer:
(c) 1

Question 20.
int m=isupper (‘a’);
The value of m is:
(a) 0
(b) m
(c) a
(d) 1
Answer:
(a) 0

Question 21.
________ used to convert the given character into its uppercase.
(a) upper( )
(b) lower( )
(c) toupper( )
(d) upppercase( )
Answer:
(c) toupper( )

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 22.
char c=toupper(‘k’);
The value of c is:
(a) K
(b) k
(c) 0
(d) C
Answer:
(a) K

Question 23.
cout<<toupper(‘B’);
The output of the statement will be:
(a) 0
(b) 1
(c) b
(d) B
Answer:
(d) B

Question 24.
__________ is used to convert the given character into its lowercase.
(a) lower( )
(b) lowercase( )
(c) tolower( )
(d) islower( )
Answer:
(c) tolower( )

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 25.
char c=tolower(‘K’);
The value of c is:
(a) c
(b) K
(c) k
(d) 1
Answer:
(c) k

Question 26.
cout<<tolower(‘b’); The output of the above statement is:
(a) B
(b) 0
(c) b
(d) 1
Answer:
(c) b

Question 27.
_______ header file to be included before using string function.
(a) strings.h
(b) string.h
(c) source.h
(d) string
Answer:
(b) string.h

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 28.
The strcpy( ) function takes arguments.
(a) one
(b) two
(c) three
(d) four
Answer:
(b) two

Question 29.
______ terminating character is copied in strcpy( ).
(a) ‘\a’
(b) ‘\\’
(c) ‘\b’
(d) ‘\0’
Answer:
(d) ‘\0’

Question 30.
_________ copies the character string pointed by the source to the memory location pointed by the target.
(a) strcpy( )
(b) strlen( )
(c) strcmp( )
(d) stracat( )
Answer:
(a) strcpy( )

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 31.
________ takes a null terminated byte string source as its argument and return its length.
(a) strlen( )
(b) length( )
(c) strlength( )
(d) stringcmp( )
Answer:
(a) strlen( )

Question 32.
_______ function used to compare two strings.
(a) compare( )
(b) stringcmp( )
(c) strcmp( )
(d) strcat( )
Answer:
(c) strcmp( )

Question 33.
If string 1 is greater than the corresponding character in string2 strcmp function returns ________ value.
(a) 0
(b) null
(c) negative
(d) positive
Answer:
(d) positive

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 34.
If string 1 is less than the corresponding character in string2 strcmp function returns _____ value.
(a) 0
(b) null
(c) negative
(d) positive
Answer:
(c) negative

Question 35.
_________ function appends copy of the character string pointed by the source to the end of string pointed by the target.
(a) strcat( )
(b) strcpy( )
(c) stringcat( )
(d) stringcopy( )
Answer:
(a) strcat( )

Question 36.
________ is used to convert the given string into uppercase letter.
(a) strupr( )
(b) toupper( )
(c) isupper( )
(d) stringupper( )
Answer:
(a) strupr( )

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 37.
_______ is used to convert the given string into lowercase letters.
(a) lower( )
(b) islower( )
(c) tolower( )
(d) strlower( )
Answer:
(d) strlower( )

Question 38.
Mathematical function includes header file.
(a) maths.h
(b) math.h
(c) math
(d) mathematical.h
Answer:
(b) math.h

Question 39.
The function that returns square root of the given argument is:
(a) sum( )
(b) squareroot( )
(c) square( )
(d) sqrt( )
Answer:
(d) sqrt( )

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 40.
______ function returns base raised to the power of exponent.
(a) power( )
(b) pow
(c) pow( )
(d) power
Answer:
(c) pow( )

Question 41.
_______ are the means to pass values from the calling function to the called function.
(a) Class
(b) Objects
(c) Functions
(d) Parameters
Answer:
(d) Parameters

Question 42.
The variables used in the function definition as parameters are known as parameters.
(a) actual
(b) informal
(c) default
(d) formal
Answer:
(d) formal

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 43.
The constants, variables or expressions used in the function call are known as ________ parameters.
(a) null
(b) actual
(c) formal
(d) copy
Answer:
(b) actual

Question 44.
The constant variable can be declared using _____ keyword.
(a) constant
(b) const
(c) void
(d) int
Answer:
(b) const

Question 45.
The ______ modifier enables to assign an initial value and cannot be changed later inside the body of the function.
(a) int
(b) signed
(c) unsigned
(d) const
Answer:
(d) const

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 46.
In C++, the arguments can be passed to function in _____ ways.
(a) one
(b) two
(c) three
(d) four
Answer:
(b) two

Question 47.
In _____ changes made to formal parameter will have no effect on the actual parameter.
(a) call by value method
(b) call by reference method
(c) function method
(d) structure method
Answer:
(a) call by value method

Question 48.
In _______ method changes made in the formal parameter will be reflected in the actual parameter.
(a) call by value
(b) call by reference
(c) arrays
(d) structure
Answer:
(b) call by reference

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 49.
______ functions execute faster but requires more memory space.
(a) String
(b) Math
(c) Iostream
(d) Inline
Answer:
(d) Inline

Question 50.
The ________ statement returns the control back to the calling statement.
(a) return
(b) call
(c) continue
(d) break
Answer:
(a) return

Question 51.
A function that calls itself is known as _______ function.
(a) inline
(b) string
(c) void
(d) recursive
Answer:
(d) recursive

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 52.
There are ________ types of scopes in C++.
(a) two
(b) three
(c) four
(d) five
Answer:
(c) four

Question 53.
A variable that is declared inside a block is called ________ variable.
(a) local
(b) global
(c) functions
(d) class
Answer:
(a) local

Question 54.
A variable that is declared inside a class is called ______ variable.
(a) object
(b) function
(c) private
(d) class
Answer:
(d) class

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 55.
A variable that is declared outside all functions called _______ variables.
(a) local
(b) global
(c) private
(d) protected
Answer:
(b) global

Question 56.
A variable declared inside a function is called _______ variables.
(a) private
(b) protected
(c) public
(d) function
Answer:
(d) function

Question 57.
Match the following:

(i) getchar( )  (a) math.h
(ii) strcpy( )  (b) ctype.h
(iii) isalpha( )  (c) stdio.h
(iv) sin( )  (d) string.h

(a) (i) – (c); (ii) – (d); (iii) – (a); (iv) – (b)
(b) (i) – (d); (ii) – (a); (iii) – (b); (iv) – (c)
(c) (i) – (a); (ii) – (b); (iii) – (d); (iv) -(c)
(d) (i) – (d); (ii) – (c); (iii) – (a); (iv – (b)
Answer:
(a) (i) – (c); (ii) – (d); (iii) – (a); (iv) – (b)

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 58.
Choose the correct statement:
(a) The pow( ) function returns the square root of the given value.
(b) The strupr( ) used to convert the string into uppercase letters.
(c) isdigit( ) check the given character is an alphabet or not.
(d) strcmp( ) finds the length of the string.
Answer:
(b) The strupr( ) used to convert the string into uppercase letters.

Question 59.
Choose the incorrect statement:
(a) The strlwr( ) function is used to convert the given string into lowercase letters.
(b) The strcmp( ) function compares the contents of the two strings.
(c) toupper( ) is used to check the given character is uppercase.
(d) puts( ) prints the string read by gets( ) function.
Answer:
(c) toupper( ) is used to check the given character is uppercase.

Question 60.
Assertion (A):
setw inserts a new line and flushes the buffer.
Reason (R):
The field width determine the minimum number of character to be written j in output.
(a) Both A and R are true and R is the correct explanation for A.
(b) Both A and R are true, but R is not the correct explanation for A.
(c) A is true, but R is false.
(d) A is false, but R is true.
Answer:
(d) A is false, but R is true.

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 61.
Choose the odd one out:
(a) endl
(b) setfill( )
(c) setprecision( )
(d) Const
Answer:
(d) Const

Question 62.
Which of the following header file defines the standard I/O predefined functions ?
(a) stdio.li
(b) math.h
(c) string.h
(d) ctype.h
Answer:
(a) stdio.li

Question 63.
Which function is used to check whether a character is alphanumeric or not. (a) isalpha( ) (b) isdigit( ) (c) isalnum( )
(d) islower( )
Answer:
(c) isalnum( )

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 64.
Which function begins the program execution?
(a) isalpha( )
(b) isdigit( )
(c) main( )
(d) islower
Answer:
(c) main( )

Question 65.
Which of the following function is with a return value and without any argument ?
(a) x=display(int, int)
(b) x=display(.)
(c) y=display(float)
(d) display(int)
Answer:
(b) x=display(.)

Question 66.
Which is return data type of the function prototype of add(int, int); ?
(a) int
(b) float
(c) char
(d) double
Answer:
(a) int

Samacheer Kalvi TN State Board 11th Computer Applications Important Questions Chapter 11 Functions

Question 67.
Which of the following is the scope operator?
(a) >
(b) &
(c) %
(d) ^
Answer:
(d) ^

TN Board 11th Computer Science Important Questions