View Single Post
  #2  
Old 14-10-2008, 02:05 AM
BSIT07-01's Avatar
BSIT07-01 BSIT07-01 is offline
Addicted to Computer


 
Join Date: Sep 2007
Location: ------------
Age: 34
Posts: 1,309
Contact Number: ---------------
Program / Discipline: BSIT
Class Roll Number: 07-01
BSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant futureBSIT07-01 has a brilliant future
Default Re: Scope of Variables C++

Static Variable

Syntax:
Code:
static int n;
we use static keyword before declaration.

One use of Static Variables is in functions,
when we want to store a value within a function, and not want to destroy it even when the function is ended...
eg: we want to know how many times a function is called.
Code:
void myfunction()
{
static int count=0;
/* Body of Our Function

*/

count++;

}
Static variable count is created when first time we call this function. And is not destroyed until execution of whole program is completed.

when ever we call this function, count is incremented by 1.
So We may easily calculate the number of times a function is executed
Reply With Quote