Explanation of Solution
Output of the Program:
The given program has been added with comments and line number.
/* Include required variables */
#include <iostream> //Line 1
using namespace std; //Line 2
/* Function prototype */
void showVar(); //Line 3
/* Main function */
int main()//Line 4
{ //Line 5
/* Loop till "count" variable is less than "10" */
for (int count = 0; count < 10; count++) //Line 6
/*Call the function "showVar()"*/
showVar(); //Line 7
/*Return the value 0*/
return 0; //Line 8
}//Line 9
/*Function definition*/
void showVar() //Line 10
{//Line 11
/* Variable "var" is declared as static "int" and assign "10" to it */
static int var = 10; //Line 12
/*Print the value "var"*/
cout << var << endl; //Line 13
/*Increment the variable "var"*/
var++; //Line 14
} //Line 15
Explanation:
The above program explains the scope of the local variable when it is declared as “static”.
“main()” function:
- In line 6, it uses the “for” loop for iterating the “count” variable equals to less than 10.
- When the value of “count” is “0”, the function “showVar()” has been called, which prints the value 10.
- When the value of “count” is “1”, the function “showVar()” has been called, which prints the value 11.
- When the value of “count” is “2”, the function “showVar()” has been called, which prints the value 12...
Trending nowThis is a popular solution!
Chapter 6 Solutions
STARTING OUT WITH C++ MPL
- Describe the performance considerations when heavily utilizing function objects.arrow_forwardIn what scenarios would it be beneficial to utilize a function object over a standard function?arrow_forwardSet-up and implementation code for a void function MaxYou are not required to write a complete C++ program but must write and submit just your responses to the four specific function related questions below: QC1: Write the heading for a void function called Max that has three intparameters: num1, num2 and greatest. The first two parameters receive data from the caller, and greatest is used to return a value as a reference parameter. Document the data flow of the parameters with appropriate comments*. QC2: Write the function prototype for the function in QC1. QC3: Write the function definition of the function in QC1 so that it returns the greatest of the two input parameters via greatest, a reference parameter. QC4: Add comments to the function definition* you wrote in QC3 that also states its precondition and postcondition.arrow_forward
- In c++ languagearrow_forwardThe types of arguments in a function call must be consistent with the types of the corresponding parameters in the function prototype’s parameter listT/Farrow_forward#include using namespace std; void myfunction(int num2, int num1); lint main() { my function (5,2); return 0; } void myfunction(int num1, int num2) {if (num1>3) cout << "A1"; else if (num1<3) cout<<"A2"; else cout<<"A3";} O A2 O A1 O A3 A1 A2 A3arrow_forward
- True or False : The concept of function abstraction hinders our code development by confusing us with the details of the function.arrow_forwardin c++, "Overload of functions" Write an overloaded function that returns a value based on a set of formal parameters: . z={ x - a; x + a - barrow_forwardExplanation: Default arguments should always be declared at the rightmost side of the parameter list but the above function has a normal variable at the rightmost side which is a syntax error, therefore the function gives an error. 1. #include int fun(int=0, int = 0); int main() { cout << fun(5); return 0; } int fun(int x, int y) { return (x+y); } а) -5 b) 0 c) 10 d) 5 2. int main() { int a=10; int b,c; b =a++; c = a; cout<arrow_forwardDefine the term void functions.arrow_forwardC++ Functions provide a means to modularize applications Write a function called "Calculate" takes two double arguments returns a double result For example, the following is a function that takes a single "double" argument and returns a "double" result double squareArea(double side){ double lArea; lArea = side * side; return lArea;}arrow_forwardA name has this scope if it is declared in the function parameter list of a function declaration without a body.arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning