Download CBSE Class 11 Computer Science Functions Notes Set B in PDF format. All Revision notes for Class 11 Computer Science have been designed as per the latest syllabus and updated chapters given in your textbook for Computer Science in Standard 11. Our teachers have designed these concept notes for the benefit of Grade 11 students. You should use these chapter wise notes for revision on daily basis. These study notes can also be used for learning each chapter and its important and difficult topics or revision just before your exams to help you get better scores in upcoming examinations, You can also use Printable notes for Class 11 Computer Science for faster revision of difficult topics and get higher rank. After reading these notes also refer to MCQ questions for Class 11 Computer Science given our website
Function: A function is a named unit of a group of statements that can be invoked from other parts of the program. The advantages of using functions are:
• Functions enable us to break a program down into a number of smaller and smaller and simpler units. This makes the program more organized and structured and easier to debug.
• It helps in reusability of code and thus reduces program size. If similar code is required at several places in the program, the use of a function allows this code to be written just once, and to be called wherever it is required.
• It helps to execute the same set of statements with different set of values.
Function Declaration/Prototype: Just as any variable is declare before it is used in a program, it is necessary to declare a function to inform the compiler that the function would be referenced at a later point in the program. Function declaration is also called function prototype.
Syntax for function declaration:
<return type> <function name> ( <data type of parameter> [<parameter name>], …. );
Example: int sum ( int, int);
A declaration (prototype) tells the compiler that later on in our program we are going to write a particular function. It also informs the compiler about:
1. the type of result to be returned;
2. the identifier of the function;
3. the number and types of parameters;
It is terminated by a semicolon.
<return type>: It is the data type of the value that is returned to the calling function after the function is executed. It can be any of the data types, available in C++.
<function name>: It is the name of the function, which is given with accordance to the naming conventions used for naming an identifier. A function is called with the help of it’s name.
<data type of parameter>: These are the data types of the parameters/inputs that the function receives when it is called. In function declaration it is optional to give the name of the parameters. The different data types specify to the compiler, the total number of parameters, and the data type of these parameters that the function will receive, when it is called (invoked).
Function definition: The function definition contains the function header and the function body i.e. the set of statements which are executed when the function is called.
Syntax for function definition:
<return type> <function name> (<data type of parameter> <name of <parameter>, …. )
return ( value / variable / expression );
int sum ( int a, int b)
int s = a + b;
Note: The return statement is used to return a value to the calling function. It is always the last statement in the function definition (if the function has return type). The data type of the value returned should match with the return type of the function.
// Example 1
// Program to find the factorial of a number using a function Fact ()
long Fact( long); // Function Prototype
cout<<”\n\tEnter a No. : “;
cout<<num<<”! = ”<<Fact(num); // Function call with num as an actual parameter
// Definition of function
long Fact (long N) // Function header with N as a Formal parameter
long I, f=1;
for( i=1; i<=N; i++)
f = f * i;
Order of Execution in the above program
main() // Execution starts from the main()
Function call to Fact() // Control is passed to the function definition of Fact()
Execution of the Fact() // All the statements in the function Definition of Fact() are executed
Execution of statement getch() // Control returns to the main(), to the statement which follows the function call statement of Fact()
Function Header: It is the first line of the function definition, which specifies the following:
• Return type of the function
• Name of the function
• Name of the parameters, along with their data types
Note: It is not terminated with semicolon.
Please click the link below to download pdf file for CBSE Class XI Computer Science Functions (1).
Click for more Computer Science Study Material ›