🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c.moderated
Article #2257

Re: Good C Interview questions?

#2257
From: Kevin Miller
Date: Wed, 13 Mar 1996 12:39
52 lines
2909 bytes
jfc@mit.edu (John Carr) writes:

>In article <4hv081$jdt@solutions.solon.com>,
>Marc Espie <espie@clipper.ens.fr> wrote:

>>>It's obvious that:
>>>	A [i] == 'l'
>>>But what is:
>>>	i [A] == ???
>>
>>>Any competent C programmer should know.
>>
>>Any *competent* C programmer should know ??? Come on, have you *ever*
>>seen this weird construct used outside of the IOCCC ?
 
Does IOCCC stand for "International Organization of Competent C Coders"?  
 
Since A[i] is turned into *(A+i), I was able to figure out on my own 
that if the second expression at the top of this post compiled, then it 
would have to produce the same result as the first one.  However, I would 
have thought that the compiler would do a check whenever it saw brackets 
to make sure that the thing before the brackets was a pointer and the 
thing inside the brackets was an integer.  However, K&R state that 
indexing is commutative, and a quick test program compiled and run 
using my (admittedly substandard) compiler confirms this.  So I learned 
something new today!  :)  

>I've used it once.  In the process I discovered that IBM's xlc compiler
>doesn't like reverse array notation -- it generates bad code.

>I think a C programmer should know that array indexing is commutative,
>but I wouldn't ask about it in an interview.  Unless I was interviewing
>somebody just out of school for a first real programming job I wouldn't
>ask detailed C syntax/semantic questions at all.  There are too many
>details of C.  It would take a long time to ask about them all, and it
>is reasonable not to know some of them.

>Q: Which has higher precedence, + or |?
>A: I don't remember, so I use parentheses.

>I really didn't remember and I've been using C for more than 10 years.
>When I need to know I take 30 seconds to write a C program to see what the
>compiler does, or read the standard, or look at gcc's parser.  (Sun's C
>compiler says + is higher than |.)  Maybe that would be a good interview
>question: ask what the precedence is and if the answer is "I don't know"
>follow up by asking: "show me how you would find out".

My answer would be:  I would just look on page 53 of Kernighan & Ritchie.  
(Since I already know said page number by heart.)  
 
                       - Kevin Jay Miller 
 ` 
Technical Details
Message-ID: <4i6flg$ot6@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
References: <4h2s1m$l8@solutions.solon.com> <4h75c1$4nh@solutions.solon.com> <4hqebv$1k1@solutions.solon.com> <4hv081$jdt@solutions.solon.com> <4hvvlg$op0@solutions.solon.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: kjm@sbphy.physics.ucsb.edu ( Kevin Miller)
Newsgroups: comp.lang.c.moderated
Subject: Re: Good C Interview questions?
Date: 13 Mar 1996 06:39:12 -0600
Organization: University of California, Santa Barbara
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4i6flg$ot6@solutions.solon.com>
References: <4h2s1m$l8@solutions.solon.com> <4h75c1$4nh@solutions.solon.com> <4hqebv$1k1@solutions.solon.com> <4hv081$jdt@solutions.solon.com> <4hvvlg$op0@solutions.solon.com>
NNTP-Posting-Host: solutions.solon.com