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++: Early Objects (10th Edition)
- What may a parameter variable be used for?arrow_forwardWhy do you need to include function prototypes in a program that contains user-defined functions? (5)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_forward
- When calling a function with several arguments, parameter order matters.arrow_forwardWhat exactly is the distinction between an argument and a parameter variable?arrow_forwardWhen invoking a function that takes several arguments, does the order in which the parameters are supplied matter? Computer sciencearrow_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