Functions     

A function is a block of code which only runs when it called.Passed data into a function is known as parameters.

Need of Function: 


  1. Function reduces the redudancy of code.
  2. Function make code modular.
  3. Function provide abstraction.

Function Creation: 

C++ provides some pre_definedd functions,such as main(),which is used to execute code.But we can also create our own functions to perform cirtain actions.
To crate a function ,specify the name of the function, followed by parentheses();.

Function Declaration and Defination:

A C++ function consists of two parts:
  • Declaration- The function's name,return type,and parameters.
  • Definition- The body of function.

                    

Function calling:

 Declared function are not executed immediately.They will executed when they are called.
 To call a function,write the function's name followed by two parenthesis () and a semicolon ;.
A function can be called multiple times.

Parameter Passing to Function:

Parameters passed to a function are called actual parameters.
Parameters recieved by function are called formal parameters.

Pass by Value : In this paracmeter passing method, values of actual parameters are copied to function's formal parameters and the two types of parameters are stored in different memory locations.So any changes made inside functions are not reflected in actual parameters of caller.

Pass by refrences : In this both actual and formal parameters refer to the same locations.So any changes made inside the function are actually reflected in actual parameters of caller.

Comments

Popular posts from this blog

Covid-19 Analysis and Visualization using Plotly Express

Artificial Intelligence (Problem Solving)

Linear Regression