Today's Lecture Includes: Header Files Scope of Variables Functions Call by Value Call by Reference
Today's Lecture Includes: Header Files Scope of Variables Functions Call by Value Call by Reference
Header Files
Scope of Variables
Functions
Call by value
Call by reference
Header Files
#include <iostream.h>
Prototype
double pi = 3.1415926;
#define pi 3.1415926
Name can be used inside a program exactly
like a variable
It cannot be used as a variable
void functionName ( )
{
{
int i ;
}
…..
}
Identifiers Important Points
Global variable
Global Variable
void f ( void )
{
cout<< “ Inside function f , i =“ << i ;
i = 20 ;
}
Example: Call by Value
int f ( int i )
{
cout << "In function f , i = " << i ;
i *= 2 ;
cout << "In function f , i is now = “ << i ;
return i ;
}
Example : Square of a Number
double square ( double x )
{ return x * x ; }
main ( )
{
double number = 123.456 ;
cout << “ The square of “ << number <<
“ is “<< square ( number ) ;
cout << “ The current value of “ <<
number << “is “ << number ;
}
Call by Reference
square ( double *x )
{
*x = *x * *x ;
}
Pointers