Have you ever got the same doubt??
- Don't worry I'll help you to get out of this
- #include<bits/stdc++.h>
- using namespace std;
- #define k 6-2
- int main()
- {
- int a;
- a = k*k*k;
- cout<<a;
- return 0;
- }
- Here #define is called macros
- It substitutes the k value with the expression next to k in code
- It won't evaluate the expression
- Many of us thinks it evaluates the expression so they will assume k = 4 and substitutes a = 4 * 4 *4 and finally they decide a = 64;
- But above approach is wrong ;
- First it will substitute the expression so k remains same as 6-4 .
- So , a = 6 - 2 * 6 - 2 * 6 - 2
- Now it will get evaluated
- As per preferences first multiplication will be done ,
- So, a = 6 - 12 - 12 - 2
- Hence a = -20
- See the video for clarification
- Ask doubts in comment box