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.