Predict the output and explain your prediction.
The following program has been partitioned into two files. The command line command for compiling this is CC B.cpp A.cpp, where CC is the name for your command line compiler. For VC++ this is CL, for Borland, this is BCC32, and for the GNU C++ compiler, this is g++. If you use an IDE (integrated development environment) you would have to place both these files in your project then click the compile button.
```
// This goes in file A.cpp
namespace
{
int func(int i)
{
return i*3;
}
int junk (int i)
{
return i*func(i);
}
// This goes in file B.cpp
#include
int func(int i)
{
return i*5;
}
int junk(int i); //from A.cpp
int main()
{
cout <<”func(5) = “ << func(5) << endl;
cout <<”junk(5) = “ << junk(5) << endl;
}
```
func(5) = 25
junk(5) = 75
The function main() calls func, passing an argument of 5. Which func? The only func available is the one in B.cpp because the func from A.cpp is unavailable, since it is within an unnamed namespace. That version of func returns its argument multiplied by 5, giving 25. The function junk is defined in A.cpp, where it calls the local func, from the unnamed namespace, which returns the argument multiplied by 3, which returns 15. The function junk returns its argument multiplied by the returned value of func, namely 5*15, which is 75.
You might also like to view...
Windows 8 provides an on-screen touch keyboard
Indicate whether the statement is true or false
To move slides, you can use either the Slide Sort view or the left hand pane
Indicate whether the statement is true or false