Functions: book back answers

19 solved questions from the end of this chapter, Class 11 Computer Science, Tamil Nadu State Board. Each answer is checked against the textbook, and you can open the page that proves it.

← Notes and quiz for Functions

SECTION – A Choose the correct answer

  1. Which of the following header file defines the standard I/O predefined functions ?

    • A) stdio.h
    • B) math.h
    • C) string.h
    • D) ctype.h
    Try it, then show the answer

    A) stdio.h

    The chapter identifies stdio.h as the header file containing standard input/output functions.

    From the book: “stdio.h is a header file that contains pre-defined “standard input/ output” functions.”

  2. Which function is used to check whether a character is alphanumeric or not.

    • A) isalpha()
    • B) isdigit()
    • C) isalnum()
    • D) islower()
    Try it, then show the answer

    C) isalnum()

    The chapter says isalnum checks whether a character is alphanumeric.

    From the book: “This function is used to check whether a character is alphanumeric or not.”

  3. Which function begins the program execution ?

    • A) isalpha()
    • B) isdigit()
    • C) main()
    • D) islower()
    Try it, then show the answer

    C) main()

    A C++ program begins execution through its main() function.

    From the book: “But, it must always have only one main() function to begin the program execution.”

  4. 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)
    Try it, then show the answer

    B) x=display()

    This form calls display without arguments and assigns its returned value to x.

    From the book: “3 x = display() calling the function with a return value and without any argument”

  5. Which is return data type of the function prototype of add(int, int); ?

    • A) int
    • B) float
    • C) char
    • D) double
    Try it, then show the answer

    A) int

    With no return type explicitly stated in the prototype, the chapter says the default return type is int.

    From the book: “by default the return value of a function in C++ is of type int when no return value is explicitly given.”

  6. Which of the following is the scope operator ?

    • A) >
    • B) &
    • C) %
    • D) ::
    Try it, then show the answer

    D) ::

    The scope resolution operator is written as ::.

    From the book: “The scope resolution operator (::) is used for the following purposes.”

SECTION-B

  1. Define Functions.

    Try it, then show the answer

    Functions are small sub-programs (blocks) that perform specific functionality.

    A large program can be divided into functions to make it easier to understand, test and check for errors.

    From the book: “A large program can be split into small sub-programs (blocks) called as functions”

  2. Write about strlen() function.

    Try it, then show the answer

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

    It counts the characters in the string, excluding the terminating null character.

    From the book: “The length does not include the null(\0) character.”

  3. What are importance of void data type.

    Try it, then show the answer

    The void data type indicates that a function does not return a value. In void fun(void), the function neither receives values from the calling program nor returns a value to it.

    The chapter also notes that a return statement without a parameter can be used in a void function to terminate it.

    From the book: “void data type indicates the compiler that the function does not return a value”

  4. What is Parameter and list its types?

    Try it, then show the answer

    Parameters are the means to pass values from the calling function to the called function. The two types are formal parameters and actual parameters (arguments).

    Variables used in a function definition are formal parameters; constants, variables or expressions used in a call are actual parameters.

    From the book: “The variables used in the function definition as parameters are known as formal parameters.”

  5. Write a note on Local Scope.

    Try it, then show the answer

    A local variable is defined within a block, which begins and ends with curly braces. Its scope is limited to that block, so it cannot be accessed outside the block where it is declared. It is created when execution enters the block and destroyed when execution leaves it.

    These restrictions define the accessibility and lifetime of a local variable.

    From the book: “The scope of a local variable is the block in which it is defined.”

  6. What is Built-in functions ?

    Try it, then show the answer

    Built-in functions are functions available in the C++ language standard library. Their tasks are already written, debugged and compiled, and their definitions are stored in header files.

    They are predefined functions ready to be used for various tasks.

    From the book: “Functions which are available in C++ language standard library.”

  7. What is the difference between isupper() and toupper() functions ?

    Try it, then show the answer

    isupper() checks whether a character is uppercase and returns 1 if true, otherwise 0. toupper() converts a character to its uppercase equivalent; an already uppercase character remains unchanged.

    One tests a character's case, while the other performs a conversion.

    From the book: “This function is used to check the given character is uppercase.”

  8. Write about strcmp() function.

    Try it, then show the answer

    The strcmp() function takes two strings and compares their contents lexicographically. The chapter's example tests the result for equality and for a value less than zero.

    It compares the contents of string1 and string2.

    From the book: “The strcmp() function takes two arguments: string1 and string2. It compares the contents of string1 and string2 lexicographically.”

  9. Write short note on pow() function in C++.

    Try it, then show the answer

    The pow() function returns a base raised to the power of an exponent. It takes two arguments: the base value and the exponent. Its return type is long double if an argument is long double; otherwise, it is double.

    For example, the chapter's program calculates pow(5, 4) as 625.

    From the book: “The pow() function returns base raised to the power of an exponent.”

  10. What are the information the prototype provides to the compiler ?

    Try it, then show the answer

    A function prototype provides the return data type, the function name and the list of formal parameters or arguments, including their data types.

    The compiler uses the prototype to check whether the function has been called correctly.

    From the book: “The above function prototype provides details about the return data type, name of the function and a list of formal parameters or arguments.”

Explain in detail

  1. Explain Call by value method with suitable example.

    Try it, then show the answer

    Call by value is a method of passing arguments to a function. The value of the actual parameter is copied into the function’s formal parameter.

    1. Copying the value: The function receives a copy of the value passed by the calling function.
    2. Changes remain local: Any changes made to the formal parameter inside the function do not affect the actual parameter.
    3. Function parameter: In the example, display(int x) receives the value of a as its parameter x.
    4. Original value is unchanged: After the function call, the value of a in main remains 5, showing that the function changed only its copy.

    Example: Enter 5 for A and call display(a). The function displays 25, while the value of a in main remains 5.

    Thus, call by value protects the actual parameter from changes made inside the called function.

    From the book: “This method copies the value of an actual parameter into the formal parameter of the function.”

  2. What are the different forms of function return? Explain with example.

    Try it, then show the answer

    A function may return a value to the calling function using the return statement. The chapter describes four forms of user-defined functions, based on whether they have a return value and parameters.

    1. No return value, no parameters: This function has return type void and takes no arguments. It performs its task without returning a value.
    2. Return value, no parameters: This function takes no arguments but returns a value to the calling function. For example, display() returns the sum of two local values.
    3. No return value, with parameters: This function has return type void and receives values through its parameters. For example, display(a,b) calculates and displays their sum.
    4. Return value, with parameters: This function receives values through parameters and returns the result to the calling function. For example, display(a,b) returns their sum.
    5. How return works: The return statement terminates the function and transfers control back to the calling statement. It may return a value, or be used without a value to terminate a void function.

    Example: int display(int x, int y) { int s=x+y; return s; }

    Thus, functions are classified by whether they return a value and whether they receive parameters.

    From the book: “The name of the function is display(), its return data type is void and it does not have any argument.”

  3. Explain scope of variable with example.

    Try it, then show the answer

    Scope refers to the accessibility of a variable. It describes the region in which a variable can be used.

    1. Types of scope: C++ has four types of scope: local, function, file and class scope.
    2. Local scope: A local variable is declared within a block, which begins and ends with curly braces. It can be accessed only within that block and is created on entry and destroyed on exit.
    3. Function scope: A variable declared within a function can be used throughout that function and its sub-blocks. Formal parameters also have function scope.
    4. File scope: A variable declared above all functions and blocks, including main(), has file scope. It is also called a global variable and lasts for the lifetime of the program.
    5. Class scope: A variable declared inside a class has class scope and is accessible within that class.
    6. Example: In the chapter’s example, file_var is declared outside all functions, so it has file scope. The variable t is declared inside an if-block, so it is local to that block and cannot be accessed from main() outside it.

    Example: The chapter declares int file_var=20; outside all functions. It also declares int t inside an if-block; the chapter shows that t is not accessible outside that block.

    A variable’s scope determines where it is accessible in a C++ program.

    From the book: “A local variable cannot be accessed from outside the block of its declaration.”

Next chapterArrays and Structures