Recently I attended an interview where they asked me to write a C program to concatenate two strings without using strcat(), strlen() and strcmp() and that function should not exceed two (2) lines.
I know how to concatenate two strings without using strcat(). But my method has nearly 15 lines. I dont know how to write it in two lines.
I expect they wanted something like this:
It doesn’t return the end of the concatenated string like the real
strcat, but that doesn’t seem to be required.I don’t necessarily know if this sort of thing is a good interview question – it shows that you can code tersely, and that you know what
strcatdoes, but that’s about it.Edit: as aib writes, the statement
…is perhaps a more conventional way of writing the second loop (instead of using
for).