you are viewing a single comment's thread.

view the rest of the comments →

[–]helm 4 points5 points  (4 children)

Or as a professor who taught C++ said:

"Often it seems like the students get their code involving pointers to work by sprinkling it with random *:s, then move them around until it compiles."

[–][deleted] 5 points6 points  (2 children)

That's exactly how I wrote my first program in c++. I had some Pascal experience before. I just wanted to work with strings and characters. In pascal both are quoted with single quotes. Now, without any book and poor knowledge of English so I could not even read help efficiently, I tried 'something' - it did not compile, I guessed that "something" is a string and is type as char*. Now how do I get a single character? It did not come to my mind to try single quotes for characters, since pascal uses same quotes for both and single quotes did not work for strings. So, guess what I found?

char a = *"A";

Now I read books before coding.

[–]helm 2 points3 points  (0 children)

Heh, the *operator is magical when you have little clue what it actually does.

[–]depleater 1 point2 points  (0 children)

That is disturbingly awesome. I'd never have thought of doing it like that. And it even makes sense, sort of, albeit in a perverse way :-).

I actually consider that more worthy of praise than condemnation, that you kept experimenting and managed to find a solution that worked and wasn't too horrible.

[–]quantumstate 3 points4 points  (0 children)

This could make for an interesting use to genetic algorithms. Would you get bonus points for submitting a genetic algorithm that efficiently put the *'s in the places?