From 3920b20718264da6232ccbd8c8d77835b1504aa3 Mon Sep 17 00:00:00 2001 From: hariom Choudhary Date: Wed, 19 Dec 2018 13:45:29 +0530 Subject: [PATCH] Example to explain working (#25137) --- guide/english/c/macros/index.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/guide/english/c/macros/index.md b/guide/english/c/macros/index.md index 94e475b85b..46f739f4d3 100644 --- a/guide/english/c/macros/index.md +++ b/guide/english/c/macros/index.md @@ -66,6 +66,15 @@ You get the equivalent of: ```C printf("Hello World!"); ``` +An example to explain how code is replaced by macros +```c +#define add(a,b) a+b +``` +Now calling : +```c +int x = 2*add(3,5)*4; +``` +Here, the value of x will be 26 because the expression will become 2*3+5*4 which evaluates to give 26. Sometimes we think that the macro will give us 3+5 i.e. 8 and the expression will become 2*8*4 but this is not the case. This shows how the code is replaced exactly. #### Special Operators in Macros One can use the special operators # (stringize) and ## (concatenate) in macros for achieving unique functionality.