logoalt Hacker News

don-code04/01/20254 repliesview on HN

I agree this seems overly principled to me.

I recall a DSP class where there was an exam with a question like (not exactly this):

> What does the following code print?

> `printf("Hello, world!");`

If you responded with:

> Hello, world!

...which - of course - the whole class did, you got the question wrong.

If you responded with:

> "Hello, world!"

...which is actually not what that would print, you got the question right.

A small band of us went to the professor and noted that, in fact, `printf("Hello, world!")` does not print the quotes. But he wanted us to show that it printed a string, and we denote strings by quotes.

This was something that we learned to do just for him - all strings had to be enclosed by quotes, to denote that they were strings. As far as I'm concerned, it served no practical purpose; we never had to differentiate strings like "Hello" from ['H', 'e', 'l', 'l', 'o', 0] or other representations.

A better example of how this could go - and not one that had anywhere near the same stakes - was a question on the entrance exam for my college radio station:

> What is the airspeed velocity of an unladen swallow?

I got this question right by answering, "Ni!"

(edit: formatting)


Replies

somat04/02/2025

Yeah that sucks, the hard life lesson where you have to swallow your pride and go "fine, I will put quotes on the infernal thing"

But... it does not print a string, a string goes into it but what comes out of the function is not that programmatic feature we call a string in any way shape or form, what comes out depends on the output device specified, it may be ink on paper, lit phosphors, or a stream of bytes. none of which can you use in your program as a string.

sprintf being a notable exception of course. there you do get a string out of it.

Update: language is weird and the more I read my statement the weirder it gets, all I can do is add this cryptic note. "When you print a string it does not produce a string", this usually means I am wrong about something.

show 1 reply
microtherion04/01/2025

Depending on your environment, the above printf might print nothing at all, because there is no trailing newline.

devnullbrain04/02/2025

I have my own, similar stories but, as a mediocre student, they were lost in the noise of my own mistakes. Nonetheless it's injustice, so I still remember it. Some people on this site were really excellent students, where these deductions really mattered. I don't know how they cope.

dudinax04/01/2025

The kind of prof who never coded a useful program in his life.