Article View: comp.lang.c.moderated
Article #2532Re: What are some tricky C questions?
From: 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/
Technical Details
Message-ID:
<4k611a$aln@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailReferences:
<4jol5v$1qs@solutions.solon.com> <4jttdi$3jm@solutions.solon.com> <4k1pks$514@solutions.solon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail From: clgonsal@undergrad.math.uwaterloo.ca (Carl Laurence Gonsalves) Newsgroups: comp.lang.c.moderated Subject: Re: What are some tricky C questions? Date: 6 Apr 1996 09:02:02 -0600 Organization: University of Waterloo Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4k611a$aln@solutions.solon.com> References: <4jol5v$1qs@solutions.solon.com> <4jttdi$3jm@solutions.solon.com> <4k1pks$514@solutions.solon.com> NNTP-Posting-Host: solutions.solon.com