0 votes 0 votes tokens passed to macros are treated as int, float or string? Programming in C programming-in-c + – aditi19 asked Sep 3, 2018 aditi19 354 views answer comment Share Follow See all 4 Comments See all 4 4 Comments reply Shaik Masthan commented Sep 3, 2018 reply Follow Share it may be anything, but note that they didn't evaluate while sending. i mean, if you call f(2,3+5,7) ===> to f(int a, int b, int c) ===> before actual parameters binding to the formal parameters, the expressions get evaluated ===> a=2, b=8,c=7 if in the case of macro, 3+5 directly bind, as it is 0 votes 0 votes aditi19 commented Sep 3, 2018 reply Follow Share I was trying sending floating point numbers as parameters. It was showing error. why? 0 votes 0 votes Shaik Masthan commented Sep 3, 2018 reply Follow Share post the code 0 votes 0 votes aditi19 commented Sep 3, 2018 reply Follow Share #include<stdio.h> #define ADD(a,b) a+b int main() { printf("%f",ADD(5.50,5.50)); return 0; } I got my mistake.. i was using %d instead of %f It's working now but thanks for the above info.. it's helpful :) 0 votes 0 votes Please log in or register to add a comment.
0 votes 0 votes Arguments to macros are simply passed as text, and after preprocessing Your code become printf("%f",ADD(5.50,5.50)); to printf("%f",5.50+5.50); And now compiler considers them as double, addition is in double, and %f is for double hence prints double value. Why%f is double? https://stackoverflow.com/questions/4264127/correct-format-specifier-for-double-in-printf Why 5.50 is double and not float? https://stackoverflow.com/questions/4353780/why-floating-point-value-such-as-3-14-are-considered-as-double-by-default-in-msv sakharam answered Sep 3, 2018 sakharam comment Share Follow See all 0 reply Please log in or register to add a comment.