Home:ALL Converter>Pre-increment in macro (C)

Pre-increment in macro (C)

Ask Time:2018-06-08T22:09:55         Author:Tomer.s

Json Formatter

Jabberwocky :

Macros work by textual replacement, so in your case\n\nMax(num1, ++num2)\n\n\nwill be replaced by following code before the actual compilation happens:\n\n((num1 > ++num2) ? num1 : ++num2)\n\n\nNow you should be able to figure out yourself what's happening.",
2018-06-08T14:12:53
Achal :

After macro replacement your foo() function looks like\n\nint foo(int num1, int num2) {\n return ((num1>++num2)?num1:++num2);\n}\n\n\nNow solve below by considering num1 value as 4 and num2 value as 3\n\n Here num2 Here num2\n become 4 becomes 5 \n | | \n((num1 > ++num2) ? num1 : ++num2)\n | \n(( 4 > 4 ) ?\n |\n false i.e it will return ++num2 as a output & which in turns return 5\n\n\nSide note, Above one is simple ternary operator & here is how it works\n\noperand-1 ? operand-2 : operand-3 ;\n\n\nfirst operand-1 is solved, if its result is true(non-zero), operand-2 will consider as output otherwise operand-3. And in your mentioned code foo() returns operand-3 which is 5.",
2018-06-08T14:15:29
yy