+ 7

Doubt (C language , question from challenges)

What is the output? #define sqr(x)x*x int main(){ printf("%d",sqr(3+1)); }

30th Oct 2018, 4:30 PM
Peter Stark
4 Answers
+ 3
Since define just copy and pastes, you have 3+1*3+1 = 3+3+1 = 7 Use #define sqr(x) ((x)*(x)) to get the intendet behavior
30th Oct 2018, 4:35 PM
Matthias
Matthias - avatar
+ 3
Thankyou mimtelf
30th Oct 2018, 4:42 PM
Peter Stark
+ 3
Oh, I didn't notice there are C challenges already đŸ˜± That's nice 😅 You can report wrong answers, then other users won't encounter the same problem in the future hopefully^^
30th Oct 2018, 4:45 PM
Matthias
Matthias - avatar
+ 2
This question has the wrong answer (9) in the c challenge.
30th Oct 2018, 4:41 PM
mimtelf
mimtelf - avatar