Programming in C++ When a function is called temporary memory is set up( for its value parameters and any local variables, and also for the functions name if the return type is not void) Then the flow of control passes to the first statement in the function,s body. The called function,s body statements are executed until one of these occurs. return statement (with or without a return value) or, closing brace of function body Then control goes back to where the function was called
11 When a function is called, temporary memory is set up ( for its value parameters and any local variables, and also for the function’s name if the return type is not void). Then the flow of control passes to the first statement in the function’s body. The called function’s body statements are executed until one of these occurs: return statement (with or without a return value), or, closing brace of function body. Then control goes back to where the function was called
Programming in C++ include <iostream> int Cube (int ); ∥ prototype using namespace std; void main() int yourNumber; arguments int myNumber; yourNumber=143 myNumber cout <<"My Number=<<myNumber cout<<"its cube is"<< Cube(my Number/< endl; cout<<“ Your number=”<< yourNumbe cout <<"its cube is"<< Cube your Number << endl 12
12 #include <iostream> int Cube ( int ) ; // prototype using namespace std; void main ( ) { int yourNumber ; arguments int myNumber ; yourNumber = 14 ; myNumber = 9 ; cout << “My Number = ”<< myNumber ; cout << “its cube is ” << Cube (myNumber) << endl ; cout << “Your Number = ”<< yourNumber ; cout << “its cube is ”<< Cube (yourNumber) << endl ; }
Programming in C++ To Compile Successfully, o before a function is called in your program, the compiler must previously process either the function's prototype, or the function's definition(heading and body) 13
13 To Compile Successfully, ❖before a function is called in your program, the compiler must previously process either the function’s prototype, or the function’s definition (heading and body)
Programming in C++ AC++ function can return %in its identifier at most 1 value of the type which was specified (called the return type) in its heading and prototype but, a void-function cannot return any value in its identifier 14
14 A C++ function can return ❖in its identifier at most 1 value of the type which was specified (called the return type) in its heading and prototype ❖but, a void-function cannot return any value in its identifier
Programming in C++ Write a void function called Display Message()which you can call from main () to describe the pollution index value it receives as a parameter. Your city describes a pollution Index less than 35 as " Pleasant 35 through60as“ Unpleasant” and above 60 as Health Hazard 15
15 Write a void function called DisplayMessage ( ) which you can call from main ( ) to describe the pollution index value it receives as a parameter. Your city describes a pollution Index less than 35 as “Pleasant”, 35 through 60 as “Unpleasant”, and above 60 as “Health Hazard