A bug question in the Sololearn game | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 7

A bug question in the Sololearn game

A couple of weeks ago I got the next question in the Sololearn game: What is the output of this code? char *str = "12345"; printf("%s", *str); (*) No output ( ) 12345 ( ) 5 ( ) 1 But all of the answers are not correct. That code is bad code. It contains a bug. And output of the code may be any value (from no output till full screen of garbage), Its behaviour depends on the platform. That code even can cause crash of the process (crash must be on linux, which catches accesses to zero page). function printf is called with "%s" specificator, which means that printf expetcs its second parameter will be pointer(!) to a zero-ending string. But instead of pointer it gets first symbol of str, which equal to '1', that is pointer to 0x31 ('1' in hex = 0x31). But values at address 0x31 and next bytes are undefined (On windows may be nothing; on small platforms, like microcontrollers, it may be system data; on linux it is access to zero page, which cause access violation....). I have sent a complaint about incorrect answer a couple of week ago, but yesterday I got this bug question again in the game. It has not been fixed.

20th Feb 2020, 7:45 AM
andriy kan
andriy kan - avatar
3 Answers
+ 7
andriy kan Yes its an buggy code and will read the value from read only memory or predefined address in library which will cause an segments fault. And garbage value will be return. Have you reported the question with viewing correct answer then mail sololearn at info@sololearn.com And upload an screenshot in the mail if you have already done so than wait for the fix as developers and Official may be busy in new updates or solving existing problems. You can upload the image of the c challenge quiz in your feed so more will view this and report that quiz with in app reporting machanism.
20th Feb 2020, 8:00 AM
DishaAhuja
DishaAhuja - avatar
+ 7
@DishaAhuja I wrote complaint using the send complaint button (with exclamation mark) in the game. It containts several varinats of complaints (Spelling errors, Invalid question, Intvalid answer... The captions may be other in Enslish). I marked it as invalid answer, and wrote in "other" explanation, why it is wrong. I can't find where I can view my complaints to send screenshot. I didn;t know that I should send it to info@sololearn.com. What the send complaint button is for? I didn't blame delevelopers or anyone, I like sololearn game. I have just posted it to see other opinions (maybe I wrong and answer is correct).
20th Feb 2020, 8:24 AM
andriy kan
andriy kan - avatar
+ 4
andriy kan Yes that's correct way but as you have submitted that couple of weeks ago so you can write an mail with the screenshot of that incorrect quiz and explaining them the reason of that quiz to be incorrect so that it can work faster and the quiz bug will be resolved.
20th Feb 2020, 9:15 AM
DishaAhuja
DishaAhuja - avatar