Talking from an European perspective, there is no fair use, and citation right is very limited, it needs to be a small part of the whole and properly attributed to source and author, and stand apart from the rest of the content as a citation(indentation, blockquote, other background, etc..)
But, the Stack Overflow ToS require everything to be licenced under CC-BY-SA license. A problem with the ToS is however that it does not specify which version of the CC-BY-SA license. It is implied by the one link in the ToS that it is CC-BY-SA 4.0 but it is not clarified which license applies to the content, since there are slight variations between all the versions between 1.0 and 4.0.
The confusion is further extended by the footer of the site which states CC-BY-SA 3.0. So conflicting messages are provided by Stack Overflow on which license to use.
But assuming we settled on the CC-BY-SA 3.0 license because that is the one that is universally communicated by the footer of every site.
All content we share on Stack Overflow needs to be CC-BY-SA 3.0. So if some code is shared under another license that is not compatible you cannot use it.
You could for example use MIT expact license code in your question/answer and sub license it as CC-BY-SA when you also comply with the MIT conditions by adding the entire MIT license with it with the copyright header. That code now has TWO licences, the MIT license AND the CC-BY-SA license you added, and people can choose which license they want to use when they use the code, but Stack Overflow has their permission to use it because you sublicensed it to CC-BY-SA, so you comply with their ToS.
Images that don't have a CC-BY-SA compatible license, you cannot use them. End of story really. If the license conditions are not compatible, and there is not a right to sublicense, you cannot use them here.
Some countries have citation laws/precedents for images, like the Netherlands https://www.iusmentis.com/auteursrecht/citeren/beeldcitaat/
But you can't really count on it to be universially applicable, because like the Netherlands it used to be very confined in how things should be cited.
Not to talk about copyright about things within the images. https://www.diyphotography.net/10-famous-landmarks-youre-allowed-photograph-commercial-use/ so if you have a screenshot of your game/movie/programming editor you have to be careful. The contents of the game/movie are protected, the layout of the programming editor may be protected under copyright law, and if it's the main part of the question and not properly attributed per citation laws, it doesn't fall under it. And, as stated before, in Europe, there is no fair use. And the commercial use does apply because Stack Overflow is a commercial entity, even if you aren't.
Right now it's OUR problem, as contributors which license the content has we post, because we are liable for breaches, and Stack Overflow can simply say "Wasn't me".
But with the new Copyright reform in the European union that will go in effect in less than two years it becomes Stack Overflows problem too.
As the directive currently stands, Stack Overflow will have to delete reported content, as it does currently, but also build a feature that will prevent the same content from ever to be submitted again. (my personal opinion as I read that directive requirement was: A simple hash of the content suffices, and simply hash match. It only needs to be an exact match of that exact content, but it's waiting on the national implements of the law how strict it will roll out)
For those who say, but Stack Overflow is in the great USA and doesn't have to listen to Europe, yes that would apply if Stack Overflow would go black on all users outside of USA. The Berne convention has it so that anything that is performed in a country has to obey that countries copyright laws. So Stack Overflow has fair use in the USA, and publish a photo of the Eiffel tower at night in the USA, but to a user accessing Stack Overflow from France it can't.
It would be better if we could choose individual parts of licenses for separate parts of code and images, and the contributor is made responsible for maintaining the licenses and made aware of the license it's contributed under, without having to unilaterally share it under CC-BY-SA, but that would make things harder for datadumps, api's etc.. what Stack Overflow provides.
So in short: if it's not CC-BY-SA or permissibly sublicenseable as CC-BY-SA you cannot and may not use it here.