II-218 Programming Concepts
takes the integer input from user and stores it into variable n.
after execution, it will clear the screen.
will calculate square of the number 4; therefore, the value returned will be 16.
is used to take a character as input from user and returns it to the variable.
6. What do you mean by user-defined functions? Briefly explain it by giving its example.
Ans: The functions defined by the user according to their requirement are called as user-defined
functions. The user can modify the function according to their requirement. They certainly understand
the internal working of the function. They have full scope to implement their own ideas in the function.
Thus, the set of such user-defined functions can be useful to another programmer. One should include
the file in which the user-defined functions are stored to call the function in the program.
Example: Let the square(9) is a user-defined function that gives the result 81. Here, user knows the
internal working of the square() function, as its source code is visible.
7. Is the main() a user-defined or library function?
Ans: Yes, the main() is a user-defined function. In the main(), required code is written. The code
may be statements or functions.
8. Why to use functions?
1. If we want to perform a task repetitively, then it is not necessary to re-write the particular block of
the program repeatedly. Shift the particular block of statements in user-defined function. The func-
tion defined can be called any number of times to perform the task.
2. Using functions, large programs are reduced to smaller ones. It is easy to debug and find out the
errors in it. It also increases readability.
9. How do functions help to reduce the program size?
Ans: By writing the functions, we can reduce the space required for the part of the program that is
repeated a number of times, by including it into a function. On the function call instead of writing the
whole code repeatedly, the control is transferred to the function.
10. Write the syntax of function definition.
Ans: Function definition begins as per format given below:
function-type function_name (argument/parameter list)
local variable declaration;
The function type indicates the return type of the value returned by the function. It may be void(),
int, ﬂoat etc. The function name is the name of the function.
M10_ITL-ESL4791_02_SE_C10.indd 218 12/22/2012 5:01:42 PM