Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6
I got 3 as output. Is that what you get? What's the correct output you are expecting and why?
16th Sep 2020, 5:50 AM
Kevin ★
16th Sep 2020, 12:51 PM
Rohit
+ 2
AteFish🇧🇩 Your code is working how it's suppose to be here. (But it's also compiler dependent) Try running this code, you'll notice that only after calling the inline function the value of x is incremented(since its post increment, try with pre increment ++x once, you'll get 3) #define un(i) (i>=0?i:-i) #include <iostream> using namespace std; inline int c(int x){ return x>=0?x:-x; } int main() { int a=2; cout<<un(a++)<<endl; int x=2; cout<<c(x++)<<endl; cout << x << endl; // x is 3 return 0; } I found a very good explanation here... https://stackoverflow.com/questions/11060968/using-the-post-increment-in-function-arguments#:~:text=When%20calling%20a%20function%20(whether,statements%20in%20the%20function%20body.
16th Sep 2020, 8:05 AM
Rohit
+ 2
Ashmaupadhyay Please do not create spam threads or add spammy comments to an existing thread. Both are seen as negative behavior. Thanks and happy coding https://code.sololearn.com/Wv5gTHy1N6Ji/?ref=app
1st Dec 2020, 12:57 AM
BroFar
BroFar - avatar