Arvind Lairenjam Arvind Lairenjam - 3 months ago 10
C Question

How does the preprocessor work in C?

Why is the answer for the below code 16? Can anybody explain the working of this program?

#define SQUARE(n) n*n
void main()
{
int j;
j =16/SQUARE(2);

printf("\n j=%d",j);
getch();
}


If we write the same code like below, then the answer is 4:

//the ans is 4 why?
#include<stdio.h>
#include<conio.h>

#define SQUARE(n) n*n

void main()
{
int j;
j =16/(SQUARE(2));

printf("\n j=%d",j);
getch();
}

Answer

you'll get

j =16/2*2; // (16 / 2) * 2 = 16