Complete the code to define a macro named SQUARE that calculates the square of a number.
#define SQUARE([1]) (([1]) * ([1])) int main() { int x = 5; int result = SQUARE(x); return 0; }
The macro argument name can be any valid identifier. Here, n is used as the argument name for clarity.
Complete the macro definition to create a macro MAX that returns the maximum of two values a and b.
#define MAX(a, b) (([1]) > (b) ? (a) : (b)) int main() { int max_val = MAX(3, 7); return 0; }
The macro compares a and b. The first operand in the comparison should be a.
Fix the error in the macro to correctly compute the cube of a number x.
#define CUBE(x) (([1]) * (x) * (x)) int main() { int c = CUBE(3); return 0; }
The macro argument x must be used consistently to compute the cube.
Fill both blanks to define a macro MIN that returns the minimum of two values x and y.
#define MIN([1], [2]) ((([1]) < ([2])) ? ([1]) : ([2])) int main() { int m = MIN(10, 20); return 0; }
The macro arguments are x and y. Use them consistently in the macro.
Fill all three blanks to define a macro SWAP that swaps two variables a and b using a temporary variable temp.
#define SWAP([1], [2], [3]) \ do { \ int [3] = [1]; \ [1] = [2]; \ [2] = [3]; \ } while(0) int main() { int x = 5, y = 10; SWAP(x, y, temp); return 0; }
The macro swaps variables a and b using a temporary variable temp.