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
- Compound assignment statements should be defined.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
- Specifically, what is the difference between a parameter variable and an argument variable in code?arrow_forwardWhat is the difference between preincrementing and postincrementing a variable?arrow_forwardPrograming Language: C++ Your time machine is capable of going forward in time up to 24 hours. The machine is configured to jump ahead in minutes. To enter the proper number of minutes into your machine, you would like a program that can take a start time (in hours, minutes, and a Boolean indicating AM or PM) and a future time (in hours, minutes, and a Boolean indicating AM or PM) and calculate the difference in minutes between the start and future time. A time is specified in your program with three variables: int hours, minutes; bool isAM; // You can also use a char, i.e. A or P for example, to represent 11:50 PM, you would store: hours = 11,minutes = 50, isAM = false or if using a char, hours = 11,minutes = 50, isAM = 'A' This means that you need six variables to store a start and future time. Write a program that allows the user to enter a start time and a future time. Include a function named computeDifference that takes the six variables as parameters that represent the start…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