Can extra spaces actually change the effect of code?

So I was just following a tutorial on YouTube, and even though I could have sworn that I replicated a line of code exactly the same as in the video, it did not replicate the effect in the same video. So I stared at the original code and mine, and I realized that my code had an erroneous space at the start. So I removed it, and that seemed to fix the problem. However, I found the idea an extra space somewhere in a line of code could alter its result so drastically rather than shoot back an error so counter to what I thought I understood about C++ that I had to post here to confirm it.

do you have example snippet, screenshot… and link to video, thanks!

and do you mean c# ?

Syntactically, whitespace has absolutely no meaning besides improving readability. This is true for almost every high-level programming language, with notable exceptions such as whitespace or Python, where indentation determines the scope of a block of code.

But within strings whitespace can make a behavioural difference. This is why everyone will tell you to stay away from indexing/finding by string, for instance GameObject.Find(“the object i want”) where a subtle difference may be hard to spot: " the object i want".

Thanks. Now it all makes sense why I keep getting errors in code from the tutorial but the code seems identical. I have a tick where I sometimes unintentionally press keys while typing. The spacebar happens the most. And the way the code is displayed in visual studiomakes it harder for me to notice them. Further evidence is sometimes the only thing that fixes errors is to paste the code from the video maker’s copy of the script, which would remove spaces. You have no idea how much easier you have made my life by confirming this.

Addendum: you can of course syntactically break code by adding whitespace, or any other invalid character. The types and keywords need to be entered precisely, so “pu blic” will be a syntax error just as “Game Object” will be. But then the code won’t even compile.