-
Notifications
You must be signed in to change notification settings - Fork 13.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix wrong C++ answer(?s) #5306
Fix wrong C++ answer(?s) #5306
Conversation
@dehre On the 44th question, You are absolutely right and I agree with that explanation. Actually, the first time I thought that answer would be either So, the right answer should be Please, add this explanation as a reference to this question so that I can submit a review. |
I'm not sure I should. An exception would be question 34 just because none of the answers seem to be totally correct. |
Alright, coming to the 34th question. Yes, the
Yes, there are some compilers on some platforms that may define the char type as unsigned by default in order to optimize code for certain types of applications. It will be a long conversation if we go with that statement. By default, the if it is unsigned then it would have been explicitly provided using I Hope, I clarified this. |
Exactly, |
thanks for your comments @golamrabbiazad I have added you to the table in front of C++. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot @dehre for your valuable contribution! Great job 👍
@all-contributors please add @dehre for design, code |
I've put up a pull request to add @dehre! 🎉 |
I think, what we discussed, is enough for the clearness. It's not that deep we are thinking about, it's a LinkedIn test. Nice to have a conversation with you, thanks!
Yes, I wish 💯 |
PR Checklist
This PR is ready for review and meets the requirements set out
in Suggestion how to contribute
DOD
Changes / Instructions
Question 28: What is the value of
x
after running this code?It seems to me that either the question or the answer is wrong.
Compiling and running this snippet with both
clang
andgcc
prints-3
:The original answer,
-7
, would have been correct given this snippet instead:@unikdahal I've seen your recent PR here, what do you think? Which compiler did you use?
Question 44: What is the result from executing this code snippet?
Original answer: Part A executes because the expression (~x || y) always results in true if y==false.
Well, it's correct that part A executes, but in my opinion the correct answer is: Part A executes because
~x
is not zero, meaning true.Assuming the boolean value is represented using one byte,
true
becomes00000001
, and flipping its bits you get11111110
, which is a non-zero value.Therefore the if-condition will always evaluate to true, no matter the value of
y
.To confirm this theory, if you compile using the
-Wbool-operation
flag, withclang
you get a warning stating: "bitwise negation of a boolean expression always evaluates to 'true'".@golamrabbiazad you recently updated this answer, what do you think?
Question 34: What is the output of this code?
Possible answers:
The result is correct on my machine too, but, according to the standard,
char
could be eithersigned
orunsigned
; in the latter case, the answer would have been: "c = -1, which is greater than 10".From the reference:
So, either I checked something wrong, or LinkedIn should update its question.
Perhaps some veteran C++ developer can provide feedback?