Skip to content
Related Articles

Related Articles

Improve Article

C | Macro & Preprocessor | Question 6

  • Difficulty Level : Easy
  • Last Updated : 28 Jun, 2021
Geek Week




#include <stdio.h>
#define square(x) x*x
int main()
{
  int x;
  x = 36/square(6);
  printf("%d", x);
  return 0;
}

(A) 1
(B) 36
(C) 0
(D) Compiler Error


Answer: (B)

Explanation: Preprocessor replaces square(6) by 6*6 and the expression becomes x = 36/6*6 and value of x is calculated as 36. Note that the macro will also fail for expressions “x = square(6-2)”

If we want correct behavior from macro square(x), we should declare the macro as

#define square(x) ((x)*(x))  


Quiz of this Question

Take a step-up from those “Hello World” programs. Learn to implement data structures like Heap, Stacks, Linked List and many more! Check out our Data Structures in C course to start learning today.
My Personal Notes arrow_drop_up
Recommended Articles
Page :