0 votes 0 votes How far is Defining a function and macro related with each other? Programming in C programming-in-c + – Devshree Dubey asked Jun 15, 2018 Devshree Dubey 597 views answer comment Share Follow See all 2 Comments See all 2 2 Comments reply srestha commented Jun 16, 2018 reply Follow Share https://www.geeksforgeeks.org/macros-vs-functions/ 1 votes 1 votes Devshree Dubey commented Jun 16, 2018 reply Follow Share @Srestha,Thank you so much.:) 1 votes 1 votes Please log in or register to add a comment.
1 votes 1 votes macros are processed before the program is compiled and function are not processed but compiled. Anil Ji answered Jun 16, 2018 Anil Ji comment Share Follow See all 0 reply Please log in or register to add a comment.
0 votes 0 votes Macro is a preprocessor directive. Means macro is called before compilation started by a compiler . Macros are of two types Object like Macro- #define NUMBERS Funtion like Macro- Inline function i.e. #define foo() In the other side function can be created at the time Macro function call(as described before) and also can create without Macro function call. Without Macro function call means it can create in compilation phase, and can create parse tree in the Lexical Analysis Phase i.e. 1st phase of a compiler https://gateoverflow.in/166357/doubt https://web.eecs.umich.edu/~prabal/teaching/eecs373-f11/readings/Preprocessor.pdf https://www.slac.stanford.edu/comp/unix/gnu-info/cpp_1.html https://www.slac.stanford.edu/comp/unix/gnu-info/m4_1.html https://see.stanford.edu/Course/CS107/206 I think now how macro works will be clear srestha answered Jun 17, 2018 • edited Jun 17, 2018 by srestha srestha comment Share Follow See all 7 Comments See all 7 7 Comments reply Devshree Dubey commented Jun 18, 2018 reply Follow Share @Srestha,Thanks a tonnes for this answer of urs. Can you explain it via a simple code to make things more clear? 0 votes 0 votes srestha commented Jun 18, 2018 reply Follow Share @Devshree Macro is just a one line definition like #define A 5 Now, in code whenever u get A, replace it with 5 It is so simple, right? 0 votes 0 votes Devshree Dubey commented Jun 18, 2018 reply Follow Share @Srestha,Here you've initialized the value of A Srestha,right? 0 votes 0 votes srestha commented Jun 19, 2018 reply Follow Share it is macro definition go through the links I have given 0 votes 0 votes Devshree Dubey commented Jun 19, 2018 reply Follow Share @Srestha,I have undergone thru the links mentioned,can you please tell me then what is the difference between initialization and macro definition? 0 votes 0 votes srestha commented Jun 20, 2018 reply Follow Share initialization int a=10; but macro is done before main() called #define a 10 https://www.includehelp.com/c/variable-initialization-in-c-programming-language.aspx 0 votes 0 votes Shaik Masthan commented Jul 26, 2018 reply Follow Share @srestha mam, Macro is just a one line definition need not to be true always... #define square(x) \ x=(x*x) this is also a macro @Devshree Dubey @Srestha,Here you've initialized the value of A ? brother, A macro can't be initialized a macro is read by the preprocessor and change the source code ( changing means replacing the macros only ) 0 votes 0 votes Please log in or register to add a comment.