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 myFunc();//Line 3
/*Main function*/
int main()//Line 4
{//Line 5
/*Variable "var" is declared as "int" data type and it is assigned with the value "100"*/
int var = 100; //Line 6
/*Print the value*/
cout << var << endl; //Line 7
/*Call the function "myFunc()"*/
myFunc();//Line 8
/*Display the value of variable "val" after calling the function*/
cout << var << endl; //Line 9
/*Return the value 0*/
return 0; //Line 10
}//Line 11
/* Function definition */
void myFunc()//Line 12
{//Line 13
/*Variable "var" is declared as "int" data type and it is assigned with the value "50"*/
int var = 50; //Line 14
/* Print the value of the variable "var" */
cout << var << endl; //Line 15
}//Line 16
Explanation:
The above program explains the scope of the local variable...
Want to see the full answer?
Check out a sample textbook solutionChapter 6 Solutions
STARTING OUT WITH C++ MPL
- #include using namespace std; || function declaration int max(int num1, int num2); int main () { // local variable declaration: int a = 100; int b = 200; int ret; I| calling a function to get max value. ret = max(a, b); cout num2) result = num1; else result = num2; return result; }arrow_forward(3) Data type Dog: (a) Define data type Dog with a single value constructor that receives two strings and an integer as the dog's name, breed, and age respectively. (b) Define a function breed that receives a Dog and returns the string that represents the breed component.arrow_forwardExercise 5 #include using namespace std/ int squareByValue ( int ); // function prototypes void squareByReference ( int * ); // function prototype with pointer as argument int main () int x = 2, z = 4; cout << "x = " << x << " before squareByValue\n" << "Value returned by squareByValue: < squareByValue ( x ) << endl << "x = " << x << after squareByValue\n" << endl; cout << "z = " << z << " before squareByReference" <arrow_forwardC++arrow_forwardPart 9 - Main Driver Function 1. Write a main driver function service () having the following interface: service : void -> void The user is asked iteratively to 'Enter "Y" or "N" if there is a vehicle to be serviced : ¹. If the response is "N", the program terminates; otherwise the regular operation of receiving and servicing customers are processed for Steward car dealership company. The program prompts the user to 'Enter Customer First Name, Customer Last Name, 24-Hr Arrival Hour, 24-Hr Arrival Minutes : 1 The information entered is checked against the Customer Register to determine if the customer is present to [P]ickup or [D] rop off a vehicle for servicing. following prompt is then provided Where the customer is dropping off a vehicle, the 'Does the Customer desire to be a Platinum Customer [Y/N]: 1arrow_forwardExercise 4 The following codes will show the use of static specifier. #include using namespace std; int assignID (void) ; int assignIDnonstatic (void); void main (void) ( int i, id; cout << "Call a function with static variable\n"; for (i-0;i<5;i++) ( id = assignID(); cout << "Student ID #" << id << endl; cout << "\nCall a function with non static variable\n"; for (i-0;i<5;i++) ( id = assignIDnonstatic (); cout << "Student ID #" << id << endl; 1. system("pause"); int assignID (veid) static int ID=03; ID++B return ID; int assignIDnonstatic (void) ( Ent ID=0: ID++: return ID;arrow_forwardC++ Programming Pleasearrow_forwardC++ pleasearrow_forwardli en aretle Let the functions fun and main be defined as int fun(int *k) { *k += 2, return (*k) - 1; } void main() { int i = 10, j = 10, suml, sum2; suml= (1/2) + fun(&i); sum2 = fun(&j) + (j/2) +i; } What are the values of sum1 and sum2 at the end of the main function. a. operands in the expressions are evaluated left to right? suml= sum2- b. operands in the expressions are evaluated right to left? suml= sum2= UYGULAMAYI BİTİR...arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning