Article View: comp.lang.c.moderated
Article #1991Re: Good C Interview questions?
From: Tony Hawkins
Date: Thu, 15 Feb 1996 15:06
Date: Thu, 15 Feb 1996 15:06
38 lines
1748 bytes
1748 bytes
:> :In article <4emato$3rd@solutions.solon.com> makholm@diku.dk (Henning
Makholm) writes:
:> :
:> : David Robinson <drobin1@po-box.mcgill.ca> writes:
:> :
:> : >Anyone have any good C interview questions for candidates
:applying
:> : >for an entry-level programming position?
:> :
:> : "Do you use gotos when you program?"
:>
:> That's a good one.
:>
:> :Here's one:
:> :
:> : Why is the following code inefficient?
:> :
:> : #include <string.h>
:> : #include <stdio.h>
:> :
:> : char s[] = "abcdefghijklmnopqrstuvwxyz";
:> : extern int check(char); /* returns 0 or 1 */
:> : int i;
:> : for (i = 0; i < strlen(s); i++) {
:> : if (check(s[i])) {
:> : putchar(s[i]);
:> : }
:> : }
:>
Isn't character-at-a-time I/O supposed to be slow?
Assuming the strlen call is optimized out of the loop, I'd say that
calling putchar several times is much slower than building a new
array & passing it to puts (or fputs) -- at the cost of some memory.
-Tony
P.S. hope I got the quotes right.
Technical Details
Message-ID:
<4fvi5f$ed7@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailReferences:
<4ec3vg$lst@solutions.solon.com> <4emato$3rd@solutions.solon.com> <4evtq8$c6l@solutions.solon.com> <4f3j90$suj@solutions.solon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail From: Tony Hawkins <hawkins@onramp.net> Newsgroups: comp.lang.c.moderated Subject: Re: Good C Interview questions? Date: 15 Feb 1996 09:06:22 -0600 Organization: On-Ramp; Individual Internet Connections; Dallas/Ft Worth/Houston, TX USA Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4fvi5f$ed7@solutions.solon.com> References: <4ec3vg$lst@solutions.solon.com> <4emato$3rd@solutions.solon.com> <4evtq8$c6l@solutions.solon.com> <4f3j90$suj@solutions.solon.com> NNTP-Posting-Host: solutions.solon.com X-Mailer: Mozilla 2.0 (X11; I; SunOS 5.5 sun4c)