25. Namespace with Variables and Functions

We have already declared a namespace MathOps with:

  • A variable int x = 10;
  • A function int square(int n) that returns n*n.
     

Your task is to:

  1. Print the value of x.
  2. Call square(x) and print the result.

     

Example

Output:

x=10
Square=100

 

Why this output?

Because the variable x is accessed with MathOps::x and the function is called with MathOps::square(10).

 

Question Significance

Demonstrates how to declare functions inside a namespace and call them.

Loading...

Input

Expected Output

x=10 Square=100