1. What is a function?
Ans: A function is a self-contained block or a sub-program containing one or more statements that
perform a particular task.
2. How a function is invoked?
Ans: The desired function is called from the main() function. The statement(s) of a called function
are written outside the main() function.
3. List the types or classify the functions supported by the C language?
Ans: C language supports the following two types of functions:
1. Library functions and
2. User-defined functions.
4. What do you mean by library functions? Briefly explain it by giving its example.
Ans: The library functions are pre-defined set of functions. Their task is limited. User should not
worry to understand the internal working of these functions. They can only use the functions but cannot
change or modify them. Source code cannot be modified.
Example: sqrt (81 ) gives result 9. Here, the user need not worry about its source code, but the result
is provided by the function.
5. List any five library functions and illustrate them with suitable examples.
Ans: There are a number of library functions are available such as printf(), which is used to
display the message, scanf(), which is used to take the input from user, clrscr(), which is used
to clear the output screen, pow() function, which is used to calculate power of the argument and
getch(), which is used take a single character as input.
For example:
prints message Hello on output screen.
M10_ITL-ESL4791_02_SE_C10.indd 217 12/22/2012 5:01:42 PM
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, float 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

Get Express Learning - Computer Fundamentals and Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.