0% found this document useful (0 votes)
7 views4 pages

Chapter 13 Functions

Function in computer
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Chapter 13 Functions

Function in computer
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Chapter 13 Functions

Multiple Choice Questions


1. Function prototype for built-in functions are specified in:
a) source files b) header files c) object files d) image files
2. Global variables are created in:
a) RAM b) ROM c) Hard Disk d) Cache
3. Which of the following is true about a function call?
a) Stops the execution of the program b) Transfers control to the called function
c) Transfers control to the main function d) Resumes the execution of the program
4. The predefined functions that are part of C-language are called:
a) user-defined b) subprograms c) subroutines d) built-in functions
5. The functions that are defined by programmer are called:
a) user-defined b) subprograms c) subroutines d) built-in functions
6. Another name for built-in function is:
a) user-defined function b) library function c) ready-made function d) None
7. A function is called with the reference of its:
a) name b) parameter c) definition d) None
8. A function:
a) may return more than one value b) may return only one value
c) cannot return any value d) None of these
9. The actual values are passed to the function in:
a) function declaration b) function call c) function definition d) All
10. Which of the following looks for the prototype of functions used in a program?
a) linker b) loader c) compiler d) parser
11. The name of actual and formal parameters:
a) may or may not be same b) must be same
c) must be different d) must be in lowercase
12. Formal arguments are also called:
a) actual arguments b) dummy arguments c) original arguments d) referenced arguments
13. The printf() is a:
a) built-in function b) user-defined function c) local function d) keyword
14. The actual body of the function is defined in:
a) function declaration b) function call c) function definition d) None
15. The last statement of the body of the function is:
a) break b) continue c) return d) shift
16. A built-in function:
a) cannot be redefined b) can be redefined c) cannot return a value d) should be redefined
17. In a C program two functions can have:
a) same name b) same parameters
c) same name and same parameters d) same name but different parameters
18. In C-language, subprograms are referred to as:
a) methods b) procedure c) functions d) modules
19. The predefined functions that are part of programming language are called:
a) library functions b) built-in functions c) user-defined functions d) both a & b
20. The parameters specified in the function header are called:
a) formal parameters b) actual parameters c) default parameters d) command line
parameters
21. ______ perform tasks that may need to be repeated many times.
a) condition b) module c) program d) function
22. If the whole logic of program is contained in main function, it is called:
a) structured programming b) un-structured programming
c) object oriented programming d) modular programming
23. Built-in functions make our task:
a) complex b) lengthy c) simple d) technical
24. The parameters passed to a function in the function call are called:
a) formal parameters b) actual parameters
c) default parameters d) command line parameters
25. Which of the following is the advantage of function?
a) easy to write program b) eliminate duplicate code
c) re-usability d) all of these
26. Function definition consists of:
a) function header b) function body c) both a & b d) none
27. The first line of function definition is called:
a) function face b) function definition c) function header d) function name
28. The region of a program in which a variable is accessible refers to its:
a) area b) scope c) function d) use
29. As soon as the control moves outside of their scope, local variables are:
a) need to declare again b) accessible to limited instructions
c) accessible d) destroyed
30. Function declaration consists of:
a) function name b) function return type c) number & type of parameters d) all
31. What is true about a function prototype?
a) also referred to as function declaration b) terminated with semicolon
c) is a single statement d) all of these
32. A function that does not return anything has return type:
a) nothing b) float c) void d) null
33. The variables declared outside all blocks are called:
a) general variables b) variables c) global variables d) global data items
34. Return type of function
int func(char x, float v, double t);
a) char b) double c) float d) int
35. The declaration int abc(void); indicates that:
a) return type is void b) return type is int
c) function takes no argument d) function takes one argument
36. Variables declared inside any function are known as:
a) global variable b) private variable c) external variable d) local variable
37. Which of the following is a valid function call?
a) funct; b) funct x,y; c) funct(); d) int funct();
38. Data can be shared between functions using:
a) local variable b) static variable c) global variable d) register variable
39. Local variables are also called:
a) automatic b) normal c) global d) none

Short question with answers

1. What is a Function or modular programming?


Ans.
A function is a complete independent program that performs a specific function. The main function calls these types of
functions according to the requirement of a program. A program may have repetition of pieces of code at various places and
it is very difficult to understand and debug larger programs. Therefore, a larger program is divided into simple and
independent modules called functions and this type of programming is called modular programming.
2. What are types of functions?
Ans.
There are two types of functions in C:
1. Built-in functions
2. User-defined functions
3. What are Built-in functions?
Ans.
These are predefined functions provided by high-level languages. All built-in functions are available in libraries and therefore
are called library functions. All the C library functions are defined in header files, which must be included while writing a C
program.
Examples: printf() and scanf() functions use stdio.h, sqrt() function uses math.h.
4. What are user-defined functions?
Ans.
The functions created by the user are called user-defined functions. There are three steps to create a user-defined function:
1. Function prototype or function declaration
2. Function definition
3. Function calling
5. What is Function Prototype or Function Declaration?
Ans.
It is a statement that provides the basic information that the compiler checks and uses a function correctly. The function
prototype (declaration) consists of the name of the function, its return type, number of parameters, and type of parameters
(arguments). Function prototype is usually written before the main function.
Syntax:
Return_type function_name(parameter list);
6. Explain the concept of Return type in function declaration.
Ans.
It represents the data type returned by the function e.g. int, float. If the function does not return any value then the
keyword void is used as return type.
7. What are Parameters (arguments)?
Ans.
The information provided to the functions is called parameters or arguments. In function declaration, we specify the type of
parameters separated by commas. If no parameter is used, the keyword void is used between the parentheses.
8. What is a Function Definition?
Ans.
Variable declaration and the function logic are implemented in function definition. The actual code of the function is called
function definition. It is written outside the main function (before or after). There are two parts of the function definition:
1. Function header
2. Function body
9. What is a Function Header?
Ans.
It is the first line of the function definition. It is similar to function declaration. It is not terminated with a semicolon.
Example:
int add(int x, int y)
10. What is a Function Body?
Ans.
Variable declaration and the function logic are implemented in the function body. It is enclosed in curly braces { }.
11. What is return Statement?
Ans.
The return statement in the function body is used to specify the value returned by a function. It is usually the last statement
in the function body. The general form of return statement is:
return value / variable / expression;
When the return statement is executed, the expression is evaluated and returned as the value of the function. Execution of
the function body stops when the return statement is executed. If the type of function is void, then there is no need of
return statement.
12. What is Function Calling process?
Ans.
It is a process that is used to invoke a function to perform a specific task. A function can be called at any point in the main
program. A function can be called with its name and correct sequence of parameters. When a function call statement is
executed, control is transferred to the function body and the statements in the function body are executed. After executing
the last statement in the function, the control is transferred to the calling function.
13. What are local variables?
Ans.
All variables that are declared within a pair of curly braces are called local variables and their scope is local. The local
variables can only be accessed in the function in which they are declared. They are not available outside the function. These
are also called automatic variables. Variables in the functions are automatically created when the function is executed and
destroyed when the function terminates.
14. What is life time of a variable?
Ans.
The lifetime of a variable is the duration in which a variable exists in memory (the creation and destruction of the memory
variable).
15. What is the scope of a variable?
Ans.
The scope of a variable refers to the region of a program in which it is accessible. The name of a variable is valid only within
its scope, not outside the scope.
16. What are global variables?
Ans.
The variables declared outside all the blocks of the program are called global variables. These are also called external
variables. These variables can be accessed in any function at any time during the execution. They are available for all the
functions in the program, following their point of declaration. The lifetime of a global variable is until the termination of the
program.

You might also like