+ 2

How defMethod is working here?

#include<bits/stdc++.h> #define defMethod(i)(i*i) using namespace std; int main() { int a,b=5; a=defMethod(b+5); cout<<a; return 0; } Output: 35

19th Aug 2019, 7:04 PM
Vishesh
3 Answers
+ 3
#define replaces text when compiled. So, defMethod(b + 5); will be replaced with (b + 5 * b + 5); If you calculate (5 + 5 * 5 + 5), it will be 35. The expression inside the parentheses isn't evaluated.
19th Aug 2019, 7:14 PM
Airree
Airree - avatar
+ 1
Well, of course it is a sequence, where an = 6n + 5 (or just a1 = 11; d = 6) That's just common sense
21st Aug 2019, 12:06 PM
Airree
Airree - avatar
0
Airree I have tried it by changing the parameter while calling with b=1,2,3,4,5 the output seems like a series. Yeah you told is absolutely correct. Thanks for helping.â˜șâ˜ș
21st Aug 2019, 12:05 PM
Vishesh