#include <iostream>
using namespace std;

// your code here: define macro SQUARE(x)
// The Macro
// We use extra parentheses around x and the whole expression 
// to prevent logic errors with inputs like (n + 1).
#define SQUARE(x) ((x) * (x))

// The Inline Function
// Inline suggests to the compiler to replace the function call 
// with the actual code to save time, while keeping type safety.
inline int square(int x) {
    return x * x;
}
// your code here: define inline function square(int x)

int main() {
    int n;
    cin >> n;

    cout << "Macro Square: " << SQUARE(n) << "\n";
    cout << "Inline Square: " << square(n) << "\n";

    return 0;
}

Solving Approach

 

 

 

 

Upvote
Downvote
Loading...

Input

5

Expected Output

Macro Square: 25 Inline Square: 25