Article 16259 of comp.unix.misc: Path: ptdcs5.al.intel.com!ornews.intel.com!chnews!ennews!asuvax!cs.utexas.edu!howland.reston.ans.net!news.sprintlink.net!agphx.agcs.com!not-for-mail From: robertsw@agcs.com (Wallace Roberts) Newsgroups: misc.jobs.misc,comp.lang.c,comp.unix.misc Subject: Re: C/UNIX knowledge tests at interview time? Followup-To: comp.lang.c Date: 16 Jan 1995 18:31:53 -0700 Organization: agcs Lines: 57 Message-ID: <3ff6m9$3fh@oscar.agcs.com> References: <3f9c03$16i@news1.digex.net> <3fcvnj$gh8@panix2.panix.com> NNTP-Posting-Host: oscar.agcs.com Xref: ptdcs5.al.intel.com misc.jobs.misc:42032 comp.lang.c:116468 comp.unix.misc:16259 kenbell@panix.com (Ken Bell) writes: :Dimitri Vulis wrote: [ ...you must snip it... ] >>Say, who can name the 3 kinds of pointers that can't be dereferenced? Well, you can't dereference a void *. You can't dereference a NULL. You can't dereference an uninitialized pointer. You can't dereference an a pointer to the element just past the end of an array array. (Your example is wrong; try "p < array + n", which should work almost everywhere, and which I think is even guaranteed, although one might quibble about only comparing piwpointers *within* the same object.) You can't dereference a freed pointer, either. If you glob NULL, uninitialized pointers, and freed pointers together as "invalid pointers", then you only have 3 kinds. :>Or, what's wrong with this function and how can it be corrected? :> :>char *numfmt(int num) :>{ :>char s[100]; :> :>sprintf("%d",s,num); :>return(s); :>} : :Maybe by exchanging the positions of the format specifier and the *char, :so it conforms to the usual definition of sprintf()'s parameter list? that's not all. think about the array 's' ... what happens to its scope when numfmt() returns? what does this imply? how would you fix this problem? :>Or, explain why the following C program doesn't work as expected and how :>it may be corrected. :> :>#include :>#include :> :>int main(void) :>{ :>time_t t; :> :>time(&t); :> :>printf(" local time is %s greenwhich time is %s", :>asctime(localtime(&t)),asctime(gmtime(&t))); :>} : :By putting a "c" in front of the "time(&t)" call, so you call a :function that actually exists? the time() function exists, that's not the problem. the problem is this: routines such as localtime(), gmtime(), & asctime() return pointers to *static* storage areas. now, think about what that implies in the above example. followups set appropriately. gears, ye wilde ryder -- robertsw@agcs.com | 86 cr250 "dirt devil" 83 v65 magna "animal" "E Pluribus Unix" | 79 it250 "mr. reliable" 82 v45 magna "elliot" "Criminals (especially tyrants) prefer unarmed victims." "...sunlight on chrome, the blur of the landscape, every nerve aware." Article 16264 of comp.unix.misc: Path: ptdcs5.al.intel.com!ornews.intel.com!chnews!ennews!asuvax!gatech!howland.reston.ans.net!news1.digex.net!digex.net!not-for-mail From: dlc@access4.digex.net (David L. Craig) Newsgroups: misc.jobs.misc,comp.lang.c,comp.unix.misc Subject: Re: C/UNIX knowledge tests at interview time? Date: 17 Jan 1995 09:06:54 -0500 Organization: Keane, Inc., Rockville, MD, USA Lines: 13 Message-ID: <3fgitu$ft3@access4.digex.net> References: <3fcvnj$gh8@panix2.panix.com> <2aV1yc12w165w@bwalk.dm.com> <3fe70q$bbd@marlin.ssnet.com> NNTP-Posting-Host: access4.digex.net Xref: ptdcs5.al.intel.com misc.jobs.misc:42055 comp.lang.c:116495 comp.unix.misc:16264 In article <3fe70q$bbd@marlin.ssnet.com>, wrote: > >At least these questions are interesting. I was recently asked what the >following program fragment does: > >char str = "Hello", *p; >p = str; *p = 'J'; > >This was to test my knowledge of C -- I had to strugle not to roll on the >floor with laughter. > ... which would have caused you to resemble a bowl of Jello in an earthquake, perhaps, thus answering the question uniquely?