You are on page 1of 1

Universiti Teknologi Malaysia

Fakulti Sains Komputer dan Sistem Maklumat

SCK1223 Programming Technique II


Semester 2, 2006/2007

Revision 1
Terms and Concept of Functions
Objective 5. Which segment of the program is a function definition?
Write the line number. _____________________
The purpose of this exercise is to determine whether you have
familiarized with the terms and concepts of functions. You will 6. What is the purpose of defining a function? You may choose
be tested on the following topics: the answer from the choices provided beside or you may write your
own.
• How a function works
______________________________________________
• Function calls and function definitions ______________________________________________
• Parameter passings
• Formal and actual parameters 7. Which segment of the program is the header of function
substract?Write the line number. _________________
Questions
8. Which segment of the program is the body of function
1. Trace the following program and write the output that substract? Write the line numbers. ________________
would be produced if the user entered input as 5.
9. What is the purpose of the return statement in function
1: #include <iostream> substract? You may choose the answer from the choices provided
2: #include <stdio> below or you may write your own.
______________________________________________
3: void substract(int &, int, int);
______________________________________________
4: int main(void)
5: { 10. The calling function (caller) in the program is _________
6: int p, q;

7: cout <<"Enter an integer number: ";


11. The called function in the program is _______________
8: cin >> q;
12. List all formal parameters used in the program.
9: substract(p, q, 2); __________________________________________
10: cout <<"Result 1: p= " <<p <<endl;

11: substract(p, 2, q); 13. List all actual parameters used in the parameter.
12: cout <<"Result 2: p= " <<p <<endl; __________________________________________
13: getchar(); 14. What type of parameter passing used for sending the first
14: return 0;
15: } parameter (i.e. p) at line 9? You may choose the answer from the
choices provided beside or you may write your own.
16: void substract(int &result, int n1, int n2) ________________________
17: {
18: result = n2 - n1;
19: return; 15. What type of parameter passing used for sending the last
20: } two parameters (i.e. q and 2) at line 9? You may choose the
answer from the choices provided beside or you may write your own.
Output: ________________________

Answers you may choose:

Function definition
Function call
2. Which segment of the program is a function declaration Function declaration
(or prototype)? Write the line number. _______________ Function prototype
By value
3. Which segment of the program are function calls? Write By reference
the line numbers. ______________________________ To call its name
To execute it
4. What is the purpose of calling to a function? You may choose To declare it
the answer from the choices provided beside or you may write your To specify tasks that should be done by the function
own. To return to the beginning of the function
______________________________________________ To return to the end of the function
______________________________________________ To return to the called function
To return to the calling function

© 2006, Jumail Bin Taliba, FSKSM, UTM, jumail@fsksm.utm.my Tutorial – Terms and Concepts of Functions 1

You might also like