Thread View: comp.lang.c.moderated
11 messages
11 total messages
Started by Abu Wawda
Mon, 01 Apr 1996 13:19
What are some tricky C questions?
Author: Abu Wawda
Date: Mon, 01 Apr 1996 13:19
Date: Mon, 01 Apr 1996 13:19
6 lines
649 bytes
649 bytes
After reading the thread on "Good C interview questions", I've got to ask people to post some tricky/trivia questions on programming in C or even programming in general. Does anyone have any? Thanks in advance. Abu Wawda wawda@scf.usc.edu
Re: What are some tricky C questions?
Author: Greg Shubin
Date: Wed, 03 Apr 1996 13:10
Date: Wed, 03 Apr 1996 13:10
14 lines
851 bytes
851 bytes
In article <4jol5v$1qs@solutions.solon.com>, wawda@chaph.usc.edu says... > >After reading the thread on "Good C interview questions", I've got to >ask people to post some tricky/trivia questions on programming in C or >even programming in general. Does anyone have any? Thanks in advance. > >Abu Wawda >wawda@scf.usc.edu Here's a little example of C's inconsistent syntax: int * i, * j, k; k = *i/*j;
Re: What are some tricky C questions?
Author: James Bonfield
Date: Wed, 03 Apr 1996 13:11
Date: Wed, 03 Apr 1996 13:11
20 lines
1140 bytes
1140 bytes
In article <4jol5v$1qs@solutions.solon.com> wawda@chaph.usc.edu (Abu Wawda) writes:
>After reading the thread on "Good C interview questions", I've got to
>ask people to post some tricky/trivia questions on programming in C or
>even programming in general. Does anyone have any? Thanks in advance.
How about explaining what following construct does. What can be said about the
values of l and i at the end?
size_t l;
int i = MAXINT;
l = sizeof(++i);
:-)
James
--
James Bonfield (jkb@mrc-lmb.cam.ac.uk) Tel: 01223 402499 Fax: 01223 412282
Medical Research Council - Laboratory of Molecular Biology,
Hills Road, Cambridge, CB2 2QH, England.
Re: What are some tricky C questions?
Author: Lawrence Kirby
Date: Fri, 05 Apr 1996 00:31
Date: Fri, 05 Apr 1996 00:31
36 lines
1716 bytes
1716 bytes
In article <4jttdi$3jm@solutions.solon.com>
jkb@mrc-lmb.cam.ac.uk "James Bonfield" writes:
>In article <4jol5v$1qs@solutions.solon.com> wawda@chaph.usc.edu (Abu Wawda)
> writes:
>>After reading the thread on "Good C interview questions", I've got to
>>ask people to post some tricky/trivia questions on programming in C or
>>even programming in general. Does anyone have any? Thanks in advance.
>
>How about explaining what following construct does. What can be said about the
>values of l and i at the end?
>
> size_t l;
> int i = MAXINT;
>
> l = sizeof(++i);
>
>:-)
Very little since MAXINT isn't defined. :-) Perhaps if you were to include
limits.h and use INT_MAX instead. If you want to add a bit of interest to
the problem you could ask the same question about:
#include <stddef.h>
#include <limits.h>
size_t l;
short i = SHRT_MAX;
l = sizeof(++i);
--
-----------------------------------------
Lawrence Kirby | fred@genesis.demon.co.uk
Wilts, England | 70734.126@compuserve.com
-----------------------------------------
Re: What are some tricky C questions?
Author: Carl Laurence Gonsalves
Date: Sat, 06 Apr 1996 15:02
Date: Sat, 06 Apr 1996 15:02
45 lines
2263 bytes
2263 bytes
In article <4k1pks$514@solutions.solon.com>,
Lawrence Kirby <fred@genesis.demon.co.uk> wrote:
>In article <4jttdi$3jm@solutions.solon.com>
> jkb@mrc-lmb.cam.ac.uk "James Bonfield" writes:
>
>>In article <4jol5v$1qs@solutions.solon.com> wawda@chaph.usc.edu (Abu Wawda)
>> writes:
>>>After reading the thread on "Good C interview questions", I've got to
>>>ask people to post some tricky/trivia questions on programming in C or
>>>even programming in general. Does anyone have any? Thanks in advance.
>>
>>How about explaining what following construct does. What can be said about the
>>values of l and i at the end?
>>
>> size_t l;
>> int i = MAXINT;
>>
>> l = sizeof(++i);
>>
>>:-)
>
>Very little since MAXINT isn't defined. :-) Perhaps if you were to include
>limits.h and use INT_MAX instead. If you want to add a bit of interest to
>the problem you could ask the same question about:
>
>#include <stddef.h>
>#include <limits.h>
>
> size_t l;
> short i = SHRT_MAX;
>
> l = sizeof(++i);
Whatever the case, one can always say l==sizeof(i) (the actual numerical
value is implementation dependant), and i remains unchanged from it's
initial value, whether that's MAXINT, INT_MAX, SHRT_MAX, FOO, 5, etc. I
think the original poster's point was that the above code does not change
the value of i, which is not obvious unless you know that sizeof does not
evaluate it's operand.
--
Carl Laurence Gonsalves - clgonsal@undergrad.math.uwaterloo.ca
Computer Science, University of Waterloo
http://www.undergrad.math.uwaterloo.ca/~clgonsal/
http://www.csclub.uwaterloo.ca/~clgonsal/
Re: What are some tricky C questions?
Author: Depeche
Date: Sat, 06 Apr 1996 15:05
Date: Sat, 06 Apr 1996 15:05
22 lines
1388 bytes
1388 bytes
wawda@chaph.usc.edu (Abu Wawda) wrote: >After reading the thread on "Good C interview questions", I've got to >ask people to post some tricky/trivia questions on programming in C or >even programming in general. Does anyone have any? Thanks in advance. If "tricky/trivia C questions" are being used as a basis of anything in a job interview, or as a way of "eliminiating" or "approving" job applicants... ...any job applicant should be rightfully offended and walk right out the door... If someone applies for a job at McDonalds are they tested on how to flip a burger if they have previous experience? In any case, for anyone who is thinking of hiring people...and thinking of "Good C interview questions"... IMO, *DON'T* To me, that's akin to handing in a resume' in ALL CAPS. Rude and trite. I wouldn't work someplace that handed me a "test"... Dep
Re: What are some tricky C questions?
Author: Lawrence Kirby
Date: Mon, 08 Apr 1996 16:08
Date: Mon, 08 Apr 1996 16:08
47 lines
2055 bytes
2055 bytes
In article <4k611a$aln@solutions.solon.com>
clgonsal@undergrad.math.uwaterloo.ca
"Carl Laurence Gonsalves" writes:
> >Very little since MAXINT isn't defined. :-) Perhaps if you were to include
> >limits.h and use INT_MAX instead. If you want to add a bit of interest to
> >the problem you could ask the same question about:
> >
> >#include <stddef.h>
> >#include <limits.h>
> >
> > size_t l;
> > short i = SHRT_MAX;
> >
> > l = sizeof(++i);
>
>Whatever the case, one can always say l==sizeof(i) (the actual numerical
>value is implementation dependant),
Right (at least where i is a scalar). Compare that with:
l = sizeof(+i);
to see the possible pitfall.
>and i remains unchanged from it's
>initial value, whether that's MAXINT, INT_MAX, SHRT_MAX, FOO, 5, etc.
or even uninitialised.
>I think the original poster's point was that the above code does not change
>the value of i, which is not obvious unless you know that sizeof does not
>evaluate it's operand.
No doubt! Some other curious examples are:
l = sizeof(i/0);
l = sizeof sizeof i;
int a[10];
l = sizeof a[100];
--
-----------------------------------------
Lawrence Kirby | fred@genesis.demon.co.uk
Wilts, England | 70734.126@compuserve.com
-----------------------------------------
Re: What are some tricky C questions?
Author: Tom Tempero
Date: Tue, 09 Apr 1996 03:34
Date: Tue, 09 Apr 1996 03:34
21 lines
1315 bytes
1315 bytes
I tend to agree with Dep. I think I would be more interested in the applicant's design methodology and how problems are approached in detail. From my perspective, I am looking for a fit of my requirements for the job (after all, I got a project to get out) and how the applicant fits in. Besides, tricky C is not what I want to see in production code. I think being cute and tricky during an interview is more for inflating the ego of the interviewer; and as pointed out; somewhat rude. If the interviewer is any good, you don't have to resort to tricks to make the final judgement. -- Cheers.... Thomas Tempero Design Acceleration, Inc tilt@designacc.com Rochester Design Center 1530 Highway 52 N, Suite 1076 Rochester, MN
Re: What are some tricky C questions?
Author: Kazimir Kylheku
Date: Tue, 09 Apr 1996 03:34
Date: Tue, 09 Apr 1996 03:34
23 lines
1371 bytes
1371 bytes
In article <4k1pks$514@solutions.solon.com>, Lawrence Kirby <fred@genesis.demon.co.uk> wrote: >Very little since MAXINT isn't defined. :-) Perhaps if you were to include >limits.h and use INT_MAX instead. If you want to add a bit of interest to >the problem you could ask the same question about: > >#include <stddef.h> >#include <limits.h> > > size_t l; > short i = SHRT_MAX; > > l = sizeof(++i); So what would it be? The result ++i does not undergo intergral promotion. A better question might be to ask about sizeof(+i), which does force integral promotion. This is quite subtle. Both the ++ and the + are defined in the unary-expression syntactic unit. The only syntactic difference is that the ++ recursively takes a unary-expression, whereas the + expects a cast-expression. --
Re: What are some tricky C questions?
Author: Kazimir Kylheku
Date: Tue, 09 Apr 1996 03:35
Date: Tue, 09 Apr 1996 03:35
31 lines
1893 bytes
1893 bytes
In article <4k6187$aoq@solutions.solon.com>, Depeche <depeche@rtd.com> wrote: >wawda@chaph.usc.edu (Abu Wawda) wrote: > > >After reading the thread on "Good C interview questions", I've got to > >ask people to post some tricky/trivia questions on programming in C or > >even programming in general. Does anyone have any? Thanks in advance. > >If "tricky/trivia C questions" are being used as a basis of anything in a job >interview, or as a way of "eliminiating" or "approving" job applicants... > >...any job applicant should be rightfully offended and walk right out the >door... > >If someone applies for a job at McDonalds are they tested on how to flip a >burger if they have previous experience? > >In any case, for anyone who is thinking of hiring people...and thinking of >"Good C interview questions"... IMO, *DON'T* > >To me, that's akin to handing in a resume' in ALL CAPS. Rude and trite. I >wouldn't work someplace that handed me a "test"... > >Dep Cool! That just leaves one more opportunity for someone like me, who wouldn't mind taking a little test to prove that I know what I'm talking about. Testing is a good way to separate the wheat from the chaff. All the other things can be faked: phony references, exaggereated resumes, degree earned by cheating your way through school or completely faked, etc. --
Re: What are some tricky C questions?
Author: Kazimir Kylheku
Date: Tue, 09 Apr 1996 03:49
Date: Tue, 09 Apr 1996 03:49
14 lines
780 bytes
780 bytes
In article <4jttd2$3iq@solutions.solon.com>, Greg Shubin <gshubin@wco.com> wrote: >Here's a little example of C's inconsistent syntax: > >int * i, * j, k; > >k = *i/*j; I think that should be: k = *i/*j*/; otherwise you have an unterminated comment! ;) --
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads