Explanation of Solution
Static local variable:
The variable which is declared inside the function with the keyword “static” is referred to as static local variables.
- The declaration of the static variable is same as the normal variable declaration, but it should be preceded with the “static” keyword in front the variable.
- A
program can have multiple static local variables in different functions.
Syntax for declaring static local variable:
Static datatype variable_name;
Example:
static int a=10;
Usage of static local variable:
The uses of static local variable are:
- It makes the function to maintain the value between the function calls.
- When a function returns, the static variables used in the function are not destroyed.
Example program:
The following example program demonstrates the usage of static local variable.
/*Include required variables*/
#include<iostream>
using namespace std;
/*Function prototype*/
void display();
/*Main function*/
int main()
{
/*Loop till "count" variable is less than "10"*/
for (int count = 0; count < 10; count++)//Line 6
/*Call the function "display()"*/
display();
/*Return the value 0*/
return 0;
}
/*Function definition*/
void display()
{
/*Variable "number" is declared as static "int" and assign "20" to it*...
Want to see the full answer?
Check out a sample textbook solutionChapter 6 Solutions
STARTING OUT WITH C++ MPL
- Code in Perl Only You are given a unique scenario and you have to solve it programmatically. Ram and Shyam are two friends. Both of them are fascinated by how plants grow. They start following Rajesh who is farmer and realize if they plant three fields simultaneously and plant the third with prime sum then the yield will be maximum. Input Output 1 59arrow_forwardCompound assignment statements must be defined.arrow_forwardWhat is the purpose of a parameter variable?arrow_forward
- (Physics) Coulomb’s Law states that the force, F, acting between two electrically charged spheres is given by this formula: F=kq1q2r2 q1isthechargeonthefirstsphere.q2isthechargeonthesecondsphere.risthedistancebetweenthecentersofthetwospheres.kisaproportionalityconstant. Write an assignment statement to calculate the force, F.arrow_forwardWhat exactly is the distinction between an argument and a parameter variable?arrow_forwardDefine the term Declaring Variables.arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
- Np Ms Office 365/Excel 2016 I NtermedComputer ScienceISBN:9781337508841Author:CareyPublisher:Cengage