Day#50 'C' Coding Challenge

Day#50 'C' Coding Challenge

What is the output of the below code?

#include<stdio.h> #define SQR(num) num*num #define num 4 void main() { int var; var = 100/SQR(5); printf("%d\n", var); }

-------------------------------------------------------

The above code tests below scenarios:

1. MACRO definition
2. Problems with MACRO definition

-------------------------------------------------------

In the above code, a MACRO, SQR(num) has been defined. 
When, var = 100/SQR(5) is executed, the output shall be, var = 100/5*5, as per operator associativity and precedence, the execution happens from left to right, so, the output shall be,

var = 20*5 = 100

Post a Comment

0 Comments