Use the following program to find the scope as mentioned below: #include using namespace std; int square( int y ); // function prototype int main() { int x = 0; for ( x = 1; x <= 75; x++ ) // loop yourrollno times cout << square( x ) << endl; // calculate square of x and output results } // end main // definition of function square int square( int y ) { return y * y ; } // end function square For the program, state the scope (either function scope, global namespace scope, block scope or function-prototype scope) of each of the following elements: a) The variable x in main. b) The variable y in square. c) The function square. d) The function main. e) The function prototype for square.
a) Function scope because it's declared inside a function
b) Block scope
c) Global namespace scope
d) Global namespace scope
e) Function-prototype scope
Comments
Leave a comment