SlideShare a Scribd company logo
1 of 22
Programming
Fundamentals
A function is a named block of code that
perform some action. The statement
written in function are executed when it is
called by its name. Each function has a
unique name. Function are the
building block of c++ programs. They are
used to perform the tasks that are
repeated many times
Importance of Function
• A program may need to repeat the same
piece of code at various places.
• It may be required to perform certain task
repeatedly.
• The program may become very large if
functions are not used.
• The real reason for using function is to
divide program into different parts.
Advantages of Functions
• Easier to Code
• Easier to Modify
• Easier to Maintain
• Reusability
• Less Programming Time
• Easier to Understand
• C++ allows the use of both internal (user-
defined) and external (Built in) functions.
• external functions are usually
grouped into specialized libraries (e.g.,
iostream, stdlib, math, etc.)
C++ Functions
Function Input and Output
A set of statements that explains what a
function does is called FUNCTION
Definition
A function definition can be written at:
• Before main() function
• After main() function
• In a separate file
Syntax of Function Definition
Return-type Function-name (parameters)
{
statement 1;
statement 2;
:
:
:
statement N;
}
Function header
Function body
Function Declaration
Function declaration is the model of a function. It is
also known as FUNCTION PROTOTYPE. It provides
information to compiler about the structure of
function to be used in program. It ends with
semicolon (;). It consists of:
• FUNCTION NAME
• FUNCTION RETURN TYPE
• NUMBERS & TYPES OF PARAMETERS
Syntax of Function Declaration
Return-type Function-name (parameters);
Indicates the
name of
function
Parameters are
the values that
are provided to a
function when the
function is called.
Example of Function Declaration &
Function Definition
Function Call
The statement that activates a function is
known as FUNCTION CALL.The following steps
take place when a function is called:
1.The control moves to the function that is
called.
2.All statements in function body are executed.
3. Control returns back to calling function.
Function Call Mechanism
Void main()
{
…….
Fun();
…….
…….
Fun();
…….
}
Void Fun()
{
…..
…..
}
Called
function
Calling
function
Function
calls
Example of Function Call
Scope of Functions
Area in which a function can be accessed is known
as SCOPE OF FUNCTION.
These are two types:
1.Local Function
A function that is declared in
another function is called Local Function.
1.Global Function
A function that is declared
outside any function is called Global Function.
Call by Value
• Call by value passes the
value of actual parameter to
formal parameter.
• Actual & formal parameter
refer to different memory
location.
• It requires more memory.
• It is less efficient.
Call by Reference
• Call by reference passes the
address of actual parameter
to formal parameter.
• Actual & formal parameter
refer to same memory
location.
• It requires less memory.
• It is more efficient.
Local Variable
• Local variables are declares
within a function.
• It can be used only in function
in which they declared.
• Local variable are destroyed
when control leave the
function.
• Local variables are used when
the vales are to be used within
a function.
Global Variable
• Global variables are declares
outside any function
• Global variables can be used
in all function.
• Global variable are destroyed
when the program is
terminated.
• Global variables are used
when values are to be shared
among different functions.
A program that calls a
function for five times
using loop & also using
static(local) variable.
#include <iostream>
Using namespace std;
Int fun();
Int main()
{ int I;
for( i=0;i<=5;i++)
fun();
return 0; }
Int fun()
{ static int n=0;
n++
cout<<“value of n
=“<<n<<endl;
}
A local variable declared with
keyword STATIC is called
STATIC VARIABLE. It is used to
increase the lifetime of local
variable.
•This program declare
function Fun().
•Function declare static
variable
•Initializes it to 0.
•The main() function calls five
time.
•Using FOR LOOP.
•Last statement display value
of “n”.
Register Variable
A variable declared with keyword register is
known as Register variable. The value of
register is stored in Registers instead of RAM
because Registers are faster than RAM so
value stored in Registers can be accessed
faster than RAM. Syntax for declaring is:
register data-type variable-name
Function Overloading
The process of declaring multiple functions
with same name but different parameters is
called FUNCTION OVERLOADING. The function
with same name must differ in one of the
following ways:
1.Numbers of parameters
2.Type of parameter
3.Sequence of parameters
Basic c++

More Related Content

What's hot

Function in c++
Function in c++Function in c++
Function in c++
Kumar
 
Inline function(oops)
Inline function(oops)Inline function(oops)
Inline function(oops)
Jay Patel
 
Chapter 11 Function
Chapter 11 FunctionChapter 11 Function
Chapter 11 Function
Deepak Singh
 
Inline function
Inline functionInline function
Inline function
Tech_MX
 

What's hot (20)

FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
predefined and user defined functions
predefined and user defined functionspredefined and user defined functions
predefined and user defined functions
 
Function Returns
Function ReturnsFunction Returns
Function Returns
 
Function & Recursion
Function & RecursionFunction & Recursion
Function & Recursion
 
Functions assignment
Functions assignmentFunctions assignment
Functions assignment
 
Inline function in C++
Inline function in C++Inline function in C++
Inline function in C++
 
Basic information of function in cpu
Basic information of function in cpuBasic information of function in cpu
Basic information of function in cpu
 
Function C++
Function C++ Function C++
Function C++
 
Functions
FunctionsFunctions
Functions
 
Function in c++
Function in c++Function in c++
Function in c++
 
Inline function(oops)
Inline function(oops)Inline function(oops)
Inline function(oops)
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
 
Ch10 Program Organization
Ch10 Program OrganizationCh10 Program Organization
Ch10 Program Organization
 
functions of C++
functions of C++functions of C++
functions of C++
 
Function Parameters
Function ParametersFunction Parameters
Function Parameters
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
Chapter 11 Function
Chapter 11 FunctionChapter 11 Function
Chapter 11 Function
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
Inline function
Inline functionInline function
Inline function
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 

Similar to Basic c++

662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf
662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf
662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf
ManiMala75
 
OOP-Module-1-Section-4-LectureNo1-5.pptx
OOP-Module-1-Section-4-LectureNo1-5.pptxOOP-Module-1-Section-4-LectureNo1-5.pptx
OOP-Module-1-Section-4-LectureNo1-5.pptx
sarthakgithub
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
miki304759
 

Similar to Basic c++ (20)

358 33 powerpoint-slides_2-functions_chapter-2
358 33 powerpoint-slides_2-functions_chapter-2358 33 powerpoint-slides_2-functions_chapter-2
358 33 powerpoint-slides_2-functions_chapter-2
 
662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf
662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf
662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf
 
OOP-Module-1-Section-4-LectureNo1-5.pptx
OOP-Module-1-Section-4-LectureNo1-5.pptxOOP-Module-1-Section-4-LectureNo1-5.pptx
OOP-Module-1-Section-4-LectureNo1-5.pptx
 
Chapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.pptChapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.ppt
 
Lecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptx
 
FUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxFUNCTIONS IN C.pptx
FUNCTIONS IN C.pptx
 
FUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxFUNCTIONS IN C.pptx
FUNCTIONS IN C.pptx
 
CHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptxCHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptx
 
Functions
FunctionsFunctions
Functions
 
CH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptxCH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptx
 
Function
Function Function
Function
 
5. Functions in C.pdf
5. Functions in C.pdf5. Functions in C.pdf
5. Functions in C.pdf
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
 
Functions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothiFunctions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothi
 
FUNCTION CPU
FUNCTION CPUFUNCTION CPU
FUNCTION CPU
 
Functions_new.pptx
Functions_new.pptxFunctions_new.pptx
Functions_new.pptx
 
3. functions modules_programs (1)
3. functions modules_programs (1)3. functions modules_programs (1)
3. functions modules_programs (1)
 
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM) FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 
Functions and modular programming.pptx
Functions and modular programming.pptxFunctions and modular programming.pptx
Functions and modular programming.pptx
 
PSPC-UNIT-4.pdf
PSPC-UNIT-4.pdfPSPC-UNIT-4.pdf
PSPC-UNIT-4.pdf
 

More from Maria Stella Solon (9)

Webpage design lesson3
Webpage design lesson3Webpage design lesson3
Webpage design lesson3
 
Webdesign
WebdesignWebdesign
Webdesign
 
Basic web dev
Basic web devBasic web dev
Basic web dev
 
MIS Support to Management
MIS Support to ManagementMIS Support to Management
MIS Support to Management
 
Management Information System
Management Information SystemManagement Information System
Management Information System
 
Professional Ethics of IT
Professional Ethics of ITProfessional Ethics of IT
Professional Ethics of IT
 
Database Management System
Database Management SystemDatabase Management System
Database Management System
 
Dbms
DbmsDbms
Dbms
 
Declaration of variables
Declaration of variablesDeclaration of variables
Declaration of variables
 

Recently uploaded

QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
httgc7rh9c
 

Recently uploaded (20)

HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Our Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdfOur Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdf
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Economic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesEconomic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food Additives
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
 
Play hard learn harder: The Serious Business of Play
Play hard learn harder:  The Serious Business of PlayPlay hard learn harder:  The Serious Business of Play
Play hard learn harder: The Serious Business of Play
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 

Basic c++

  • 2. A function is a named block of code that perform some action. The statement written in function are executed when it is called by its name. Each function has a unique name. Function are the building block of c++ programs. They are used to perform the tasks that are repeated many times
  • 3. Importance of Function • A program may need to repeat the same piece of code at various places. • It may be required to perform certain task repeatedly. • The program may become very large if functions are not used. • The real reason for using function is to divide program into different parts.
  • 4. Advantages of Functions • Easier to Code • Easier to Modify • Easier to Maintain • Reusability • Less Programming Time • Easier to Understand
  • 5. • C++ allows the use of both internal (user- defined) and external (Built in) functions. • external functions are usually grouped into specialized libraries (e.g., iostream, stdlib, math, etc.) C++ Functions
  • 6.
  • 8. A set of statements that explains what a function does is called FUNCTION Definition A function definition can be written at: • Before main() function • After main() function • In a separate file
  • 9. Syntax of Function Definition Return-type Function-name (parameters) { statement 1; statement 2; : : : statement N; } Function header Function body
  • 10. Function Declaration Function declaration is the model of a function. It is also known as FUNCTION PROTOTYPE. It provides information to compiler about the structure of function to be used in program. It ends with semicolon (;). It consists of: • FUNCTION NAME • FUNCTION RETURN TYPE • NUMBERS & TYPES OF PARAMETERS
  • 11. Syntax of Function Declaration Return-type Function-name (parameters); Indicates the name of function Parameters are the values that are provided to a function when the function is called.
  • 12. Example of Function Declaration & Function Definition
  • 13. Function Call The statement that activates a function is known as FUNCTION CALL.The following steps take place when a function is called: 1.The control moves to the function that is called. 2.All statements in function body are executed. 3. Control returns back to calling function.
  • 14. Function Call Mechanism Void main() { ……. Fun(); ……. ……. Fun(); ……. } Void Fun() { ….. ….. } Called function Calling function Function calls
  • 16. Scope of Functions Area in which a function can be accessed is known as SCOPE OF FUNCTION. These are two types: 1.Local Function A function that is declared in another function is called Local Function. 1.Global Function A function that is declared outside any function is called Global Function.
  • 17. Call by Value • Call by value passes the value of actual parameter to formal parameter. • Actual & formal parameter refer to different memory location. • It requires more memory. • It is less efficient. Call by Reference • Call by reference passes the address of actual parameter to formal parameter. • Actual & formal parameter refer to same memory location. • It requires less memory. • It is more efficient.
  • 18. Local Variable • Local variables are declares within a function. • It can be used only in function in which they declared. • Local variable are destroyed when control leave the function. • Local variables are used when the vales are to be used within a function. Global Variable • Global variables are declares outside any function • Global variables can be used in all function. • Global variable are destroyed when the program is terminated. • Global variables are used when values are to be shared among different functions.
  • 19. A program that calls a function for five times using loop & also using static(local) variable. #include <iostream> Using namespace std; Int fun(); Int main() { int I; for( i=0;i<=5;i++) fun(); return 0; } Int fun() { static int n=0; n++ cout<<“value of n =“<<n<<endl; } A local variable declared with keyword STATIC is called STATIC VARIABLE. It is used to increase the lifetime of local variable. •This program declare function Fun(). •Function declare static variable •Initializes it to 0. •The main() function calls five time. •Using FOR LOOP. •Last statement display value of “n”.
  • 20. Register Variable A variable declared with keyword register is known as Register variable. The value of register is stored in Registers instead of RAM because Registers are faster than RAM so value stored in Registers can be accessed faster than RAM. Syntax for declaring is: register data-type variable-name
  • 21. Function Overloading The process of declaring multiple functions with same name but different parameters is called FUNCTION OVERLOADING. The function with same name must differ in one of the following ways: 1.Numbers of parameters 2.Type of parameter 3.Sequence of parameters