Re: Why multiplication not allowed?

From: Sean Kenwrick (skenwrick_at_hotmail.com)
Date: 01/07/04


Date: Wed, 7 Jan 2004 13:56:13 +0000 (UTC)


"Joona I Palaste" <palaste@cc.helsinki.fi> wrote in message
news:btf1cq$22o$1@oravannahka.helsinki.fi...
> Sean Kenwrick <skenwrick@hotmail.com> scribbled the following:
> > Your solution above is correct but can you figure out why the following
code
> > is invalid (which it is):
>
> > *k = *k/*j;
>
> > assuming k and j are pointers to ints that have been correctly
> > initialized....
>
> Are you testing our knowledge? The C tokeniser thinks of the /* as the
> start of a comment, so it ends up being:
> *k = *k
> which is a syntax error because the lack of a terminating semicolon.
> Were you thinking of using it in some way like this?
> *k = *k/*j; /* make sure the value of *k stays in bounds */
> +0; /* this is just a dummy */

Yeah you got it. By dividing *k by *j (without spaces) you get a syntax
error.

*k=*k/*j;

you get a syntax error because the /* starts a comment. I was given this
as a question in an interview for a job when I was a student (and I didn't
get the question right (or the job!)).

But I think the reason I didn't get the job was because one of the other
questions the interviewer asked me was to tell him what was wrong with the
following statement:

i=+i;

I said that there was nothing wrong with it, but the interviewer claimed
that it was an ambiguous statement because it could mean adding i to itselt
or setting i to +i. I got into an argument with him saying that he must
be confused with i+=i; but he was adament he was right and got annoyed that
I was disagreeing wih him.

Afterwards I wondered whether this might have been some kind of syntax left
over from a very early incarnation of C which was subsequently dropped.
Perhaps the members of this group could enlighten me about this since I
think that this guy was just a complete idiot.

The last question he asked was for me to declare a pointer to a funtion that
returned a pointer to a function that returned a pointer to a char.
Needless to say, without my K&R book to hand I messed that up as well (but
by now I got the feeling that this guy was just being mean).

In the end they gave the job to a female friend of mine who by her own
admission was not a great programmer (she got me to do all her programming
assignments in return for her doing all my essay assignments).

Sean



Relevant Pages

  • cannot install p5-Apache-SubProcess on freeBSD 5.4
    ... mod_perl.c:235: error: syntax error before ')' token ... mod_perl.c:781: warning: passing arg 1 of `Perl_newSVpv' makes pointer from integer without a cast ...
    (freebsd-questions)
  • Re: ML line number
    ... "SYNTAX ERROR IN LINE #" but i cannot seem to manipulate ... the zero page pointer for the current line number the error occured ... ;now we have our string pointed by AY, usually $0100, but just to be sure... ... sta $fb ...
    (comp.sys.cbm)
  • Re: Newbie question about "malloc" ???
    ... > but what's the hint with the Dynamic Memory Allocation ??? ... Syntax error: can't leftshift by a pointer value ...
    (comp.lang.c)
  • Re: Another dynamic memory doubt
    ... That line is a syntax error. ... If you create storage and return a pointer to that storage, ... not unless the calling routine will never ...
    (comp.lang.c)
  • Re: Another dynamic memory doubt
    ... That line is a syntax error. ... If you create storage and return a pointer to that storage, ... not unless the calling routine will never ...
    (comp.lang.c)