CBSE Class 11 Computer Science Functions Notes Set B

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>, …. )

{

Statement 1;

Statement 2;

:

return ( value / variable / expression );

}

Example:

int sum ( int a, int b)

{

int s = a + b;

return s;

}

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 ()

#include<iostream.h>

#include<conio.h>

long Fact( long); // Function Prototype

void main()

{

long num;

clrscr();

cout<<”\n\tEnter a No. : “;

cin>>num;

cout<<num<<”! = ”<<Fact(num); // Function call with num as an actual parameter

getch();

}

// Definition of function

long Fact (long N) // Function header with as a Formal parameter

{

long I, f=1;

Function Body

for( i=1; i<=N; i++)

f = f * i;

return f;

}

class_12_computer_concept_5

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.

Function Body: It is the set of statements, which are executed when the function is called.

Function Call: It is the statement in the calling function, through which the control is passed to the function definition of another function. This will execute the statements is the called function and then the control is returned back to the statement in the calling function, which follows the function call statement. The function call consists of the function name, followed by actual parameters, if any, enclosed in parentheses.

Calling Function: The function, which calls a function is called the calling function. In the above example main() is the calling function.
 
Called Function: The function which is called by anther function is known as the called function.

Formal Parameter: The parameters mentioned in the function header are called formal parameter.

Actual Parameter: Values/Variables which are used while making a call to the function are called actual parameter.
 
Difference between call by value and call by reference

 CBSE Class XI Computer Science Functions (1) 1

// Program to illustrate the invoking of a function using call by value
// and call by reference methods
#include<iostream.h>
#include<conio.h>
// Function to swap the values of two variables,
// where both the parameters are value parameters
void swapv ( int a, int b)
{
int temp = a;
a = b;
b = temp;
cout<<” Displaying the formal parameters of swapv () function “<<endl;
cout<<a<<”\t”<<b<<endl;
}
// Function to swap the values of two variables,
// where both the parameters are variable parameters
void swapr( int&b, int&b)
{
int temp = a;
a = b;
b = temp;
cout<<” Displaying the formal parameters of swapr () function “<<endl;
cout<<a<<”\t”<<b<<endl;
}
void main()
{
clrscr();
int x=5, y=7;
swapv(x,y);
cout<<”The values of actual parameters after calling the swapv() function”<<endl;
cout<<x<<”\t”<<y<<endl;
swapr(x,y);
cout<<”The values of actual parameters after calling the swapr() function”<<endl;
cout<<x<<”\t”<<y<<endl;
getch();
}
CBSE Class XI Computer Science Functions (1) 2
 

Please click the link below to download pdf file for CBSE Class XI Computer Science Functions (1).

Tags: 

 


Click to View or Download pdf file
Click for more Computer Science Study Material

Latest NCERT & CBSE News

Read the latest news and announcements from NCERT and CBSE below. Important updates relating to your studies which will help you to keep yourself updated with latest happenings in school level education. Keep yourself updated with all latest news and also read articles from teachers which will help you to improve your studies, increase motivation level and promote faster learning

Moderation of Marks Class 11 and 12 Board Exams

The portal for moderation and finalization of results for Class-12 is being opened from 16.07.2021 to 22.07.2021. As Board has to declare the result latest by 31.07.2021, schools have been requested to follow the schedule strictly and complete the moderation within...

CBSE Board Examination Scheme of Assessment 2021 2022

A. Academic session to be divided into 2 Terms with approximately 50% syllabus in each term: The syllabus for the Academic session 2021-22 will be divided into 2 terms by following a systematic approach by looking into the interconnectivity of concepts and topics by...

CBSE asks schools to load Class 12 Internal Assessment Marks

This has a reference to the letter no CBSE/COORD/2021 dated 11.02.2021 regarding conduct of the School-Based Assessment (Internal Assessment/Practical/ Project) of Class-XII and uploading the marks by 11.06.2021. It has been observed that some schools have not been...

FAQs on Policy for Tabulation of Marks for Class 10 Board Exams

ON POLICY Question.1 How CBSE will declare the result of Class-X? Answer. Results of Class X Board will be declared on the basis of an objective criterion developed by the Board vide Notification no.CBSE/CE/2021 dated 01.05.2021. Question.2. If any candidate is not...

CBSE Class 12 Evaluation Criteria 2021

SUMMARY OF THE POLICY FOR TABULATION OF MARKS FOR CLASS XII BOARD EXAMINATIONS 2021   1(a) Due to cancellation of the Board examinations, the assessment of theory portion of 80/70/60/50/30 marks will be done by the school based on the following:     Class...

×
Studies Today