SlideShare a Scribd company logo
1 of 14
RETURNING FROM A FUNCTION A FUNCTION TERMINATES WHEN EITHER A RETURN STATEMENT IS ENCOUNTERED OR THE LAST STATEMENT IN THE FUNCTION IS EXECUTED.
USE OF RETURN STATEMENT ,[object Object],[object Object],[object Object]
3 TYPES OF FUNCTION IN C++ ,[object Object],[object Object],[object Object]
RETURNING BY REFERENCE
SCOPE RULES The program part(s) in which a particular piece of code or a data value ( e.g. variable, function ) can be accessed is known as the piece-of-code’s or variable’s scope.
4 kinds of scope in C++ ,[object Object],[object Object],[object Object],[object Object]
Variable Scope int g = 10; // global variable void main ( ) { clrscr( ); int m = 20;  // function scope void func ( void ); { int b = 30; // local scope cout << “  “ <<b; cout<< “ ” << m; }
cout<< “  “ << g; cout<< “ “<<m; cout<<“”<< b; // incorrect since var. of block cout<<”” << f; // incorrect var. of function func func ( ); getch (); } void func ( void ) { int f = 40; cout < < “  “ << f; cout << “  “<< g; cout << “  “<< m; // incorrect since var. of fn. main. }
OUTPUT 30 20 10 20 40 10
FUNCTION SCOPE void global-fn ( void ); // global / file scope void main ( ) { void internal-fn ( void );  // fn. Scope for main void  internal–fn-2 ( void ) // fn. Scope for main global-fn ( );  // can call global fn. internal-fn ( );  // fn. Of main internal-fn2( );  // fn. Of main sub-internal-fn ( );  // incorrect b/c outside the scope }
void global-fn( void ) { cout<<“ this is a global fn “; } void internal-fn ( void ) { void sub-internal-fn ( void ); // fn. Scope of internal-fn cout<< “ this is an internal fn. “; global-fn ( ); // can call global fn. sub-internal-fn( ); // can call b/c fn of internal-fn internal-fn-2 ( ); // incorrect b/c fn. of main } void sub-internal-fn ( void ) { cout<<“ sub internal fn”; }
void internal-fn-2 ( void ) { cout<< “ internal – fn –2 “; } OUTPUT This is global fn.  This is an internal fn. Global-fn  sub-internal fn  internal fn2
Example of same varibale name as Formal and Actual Parameters void main ( ) { clrscr( ); void same ( int ); int a = 50; same ( a ); cout<<“ n “ << a; getch(); } void same ( int a ) { a = 60; cout<< “  ‘ << a; }
Example of Local  and Global variable having the same name. int a = 20; void main ( ) { int a = 50; cout << “local var a : “<<a; cout<< “ global var a : “<< : : a; } OUTPUT:  50 20 NOTE:   You need to use : :  ( scope resolution operator to refer to Global variable

More Related Content

What's hot

Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programmingTejaswiB4
 
Storage Class Specifiers in C++
Storage Class Specifiers in C++Storage Class Specifiers in C++
Storage Class Specifiers in C++Reddhi Basu
 
Storage classes in C
Storage classes in C Storage classes in C
Storage classes in C Self employed
 
More on Lex
More on LexMore on Lex
More on LexTech_MX
 
Storage classes in c++
Storage classes in c++Storage classes in c++
Storage classes in c++Jaspal Singh
 
Storage Classes and Functions
Storage Classes and FunctionsStorage Classes and Functions
Storage Classes and FunctionsJake Bond
 
File Handling and Command Line Arguments in C
File Handling and Command Line Arguments in CFile Handling and Command Line Arguments in C
File Handling and Command Line Arguments in CMahendra Yadav
 
Command line arguments
Command line argumentsCommand line arguments
Command line argumentsAshok Raj
 
Amit user defined functions xi (2)
Amit  user defined functions xi (2)Amit  user defined functions xi (2)
Amit user defined functions xi (2)Arpit Meena
 
Recursive Function
Recursive FunctionRecursive Function
Recursive FunctionHarsh Pathak
 
11 lec 11 storage class
11 lec 11 storage class11 lec 11 storage class
11 lec 11 storage classkapil078
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c languagetanmaymodi4
 

What's hot (20)

Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
 
Storage Class Specifiers in C++
Storage Class Specifiers in C++Storage Class Specifiers in C++
Storage Class Specifiers in C++
 
Storage classes in C
Storage classes in C Storage classes in C
Storage classes in C
 
Header files in c
Header files in cHeader files in c
Header files in c
 
Storage class in C Language
Storage class in C LanguageStorage class in C Language
Storage class in C Language
 
Function & Recursion
Function & RecursionFunction & Recursion
Function & Recursion
 
Storage classes
Storage classesStorage classes
Storage classes
 
More on Lex
More on LexMore on Lex
More on Lex
 
Storage classes in c++
Storage classes in c++Storage classes in c++
Storage classes in c++
 
Storage Classes and Functions
Storage Classes and FunctionsStorage Classes and Functions
Storage Classes and Functions
 
File Handling and Command Line Arguments in C
File Handling and Command Line Arguments in CFile Handling and Command Line Arguments in C
File Handling and Command Line Arguments in C
 
user defined function
user defined functionuser defined function
user defined function
 
Command line arguments
Command line argumentsCommand line arguments
Command line arguments
 
C++ nots
C++ notsC++ nots
C++ nots
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Amit user defined functions xi (2)
Amit  user defined functions xi (2)Amit  user defined functions xi (2)
Amit user defined functions xi (2)
 
Recursive Function
Recursive FunctionRecursive Function
Recursive Function
 
11 lec 11 storage class
11 lec 11 storage class11 lec 11 storage class
11 lec 11 storage class
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c language
 
Recursion in c
Recursion in cRecursion in c
Recursion in c
 

Viewers also liked

Viewers also liked (6)

Programming Methodology
Programming MethodologyProgramming Methodology
Programming Methodology
 
Structures
StructuresStructures
Structures
 
Wild Cards
Wild CardsWild Cards
Wild Cards
 
Cso Latest
Cso LatestCso Latest
Cso Latest
 
Computer Fundamentals
Computer FundamentalsComputer Fundamentals
Computer Fundamentals
 
Arrays
ArraysArrays
Arrays
 

Similar to RETURNING FROM FUNCTIONS

Chapter 11 Function
Chapter 11 FunctionChapter 11 Function
Chapter 11 FunctionDeepak Singh
 
What is storage class
What is storage classWhat is storage class
What is storage classIsha Aggarwal
 
Operator Overloading and Scope of Variable
Operator Overloading and Scope of VariableOperator Overloading and Scope of Variable
Operator Overloading and Scope of VariableMOHIT DADU
 
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxSangeetaBorde3
 
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)Mansi Tyagi
 
Latest C Interview Questions and Answers
Latest C Interview Questions and AnswersLatest C Interview Questions and Answers
Latest C Interview Questions and AnswersDaisyWatson5
 
Data structure scope of variables
Data structure scope of variablesData structure scope of variables
Data structure scope of variablesSaurav Kumar
 
C notes diploma-ee-3rd-sem
C notes diploma-ee-3rd-semC notes diploma-ee-3rd-sem
C notes diploma-ee-3rd-semKavita Dagar
 
Oop lect3.pptx
Oop lect3.pptxOop lect3.pptx
Oop lect3.pptxMrMudassir
 
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptxC-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptxSKUP1
 
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptxC-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptxLECO9
 
Chapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.pptChapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.pptAmanuelZewdie4
 
Basic construction of c
Basic construction of cBasic construction of c
Basic construction of ckinish kumar
 

Similar to RETURNING FROM FUNCTIONS (20)

Chapter 11 Function
Chapter 11 FunctionChapter 11 Function
Chapter 11 Function
 
What is storage class
What is storage classWhat is storage class
What is storage class
 
Function in C++
Function in C++Function in C++
Function in C++
 
Operator Overloading and Scope of Variable
Operator Overloading and Scope of VariableOperator Overloading and Scope of Variable
Operator Overloading and Scope of Variable
 
C functions list
C functions listC functions list
C functions list
 
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
 
08 -functions
08  -functions08  -functions
08 -functions
 
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)
 
Lecture 13 - Storage Classes
Lecture 13 - Storage ClassesLecture 13 - Storage Classes
Lecture 13 - Storage Classes
 
Function
FunctionFunction
Function
 
Latest C Interview Questions and Answers
Latest C Interview Questions and AnswersLatest C Interview Questions and Answers
Latest C Interview Questions and Answers
 
Data structure scope of variables
Data structure scope of variablesData structure scope of variables
Data structure scope of variables
 
C notes diploma-ee-3rd-sem
C notes diploma-ee-3rd-semC notes diploma-ee-3rd-sem
C notes diploma-ee-3rd-sem
 
Oop lect3.pptx
Oop lect3.pptxOop lect3.pptx
Oop lect3.pptx
 
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptxC-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
 
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptxC-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
 
Chapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.pptChapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.ppt
 
User defined functions in matlab
User defined functions in  matlabUser defined functions in  matlab
User defined functions in matlab
 
Basic construction of c
Basic construction of cBasic construction of c
Basic construction of c
 
Unit iii
Unit iiiUnit iii
Unit iii
 

Recently uploaded

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 

RETURNING FROM FUNCTIONS

  • 1. RETURNING FROM A FUNCTION A FUNCTION TERMINATES WHEN EITHER A RETURN STATEMENT IS ENCOUNTERED OR THE LAST STATEMENT IN THE FUNCTION IS EXECUTED.
  • 2.
  • 3.
  • 5. SCOPE RULES The program part(s) in which a particular piece of code or a data value ( e.g. variable, function ) can be accessed is known as the piece-of-code’s or variable’s scope.
  • 6.
  • 7. Variable Scope int g = 10; // global variable void main ( ) { clrscr( ); int m = 20; // function scope void func ( void ); { int b = 30; // local scope cout << “ “ <<b; cout<< “ ” << m; }
  • 8. cout<< “ “ << g; cout<< “ “<<m; cout<<“”<< b; // incorrect since var. of block cout<<”” << f; // incorrect var. of function func func ( ); getch (); } void func ( void ) { int f = 40; cout < < “ “ << f; cout << “ “<< g; cout << “ “<< m; // incorrect since var. of fn. main. }
  • 9. OUTPUT 30 20 10 20 40 10
  • 10. FUNCTION SCOPE void global-fn ( void ); // global / file scope void main ( ) { void internal-fn ( void ); // fn. Scope for main void internal–fn-2 ( void ) // fn. Scope for main global-fn ( ); // can call global fn. internal-fn ( ); // fn. Of main internal-fn2( ); // fn. Of main sub-internal-fn ( ); // incorrect b/c outside the scope }
  • 11. void global-fn( void ) { cout<<“ this is a global fn “; } void internal-fn ( void ) { void sub-internal-fn ( void ); // fn. Scope of internal-fn cout<< “ this is an internal fn. “; global-fn ( ); // can call global fn. sub-internal-fn( ); // can call b/c fn of internal-fn internal-fn-2 ( ); // incorrect b/c fn. of main } void sub-internal-fn ( void ) { cout<<“ sub internal fn”; }
  • 12. void internal-fn-2 ( void ) { cout<< “ internal – fn –2 “; } OUTPUT This is global fn. This is an internal fn. Global-fn sub-internal fn internal fn2
  • 13. Example of same varibale name as Formal and Actual Parameters void main ( ) { clrscr( ); void same ( int ); int a = 50; same ( a ); cout<<“ n “ << a; getch(); } void same ( int a ) { a = 60; cout<< “ ‘ << a; }
  • 14. Example of Local and Global variable having the same name. int a = 20; void main ( ) { int a = 50; cout << “local var a : “<<a; cout<< “ global var a : “<< : : a; } OUTPUT: 50 20 NOTE: You need to use : : ( scope resolution operator to refer to Global variable
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.