C question -- Know the answers to the following

Discussion in 'C Programming' started by mluvw47@gmail.com, Oct 3, 2005.

  1. Guest

    Know the answers to the following?

    Line Contains

    50 char *b, q, *r;
    200 b = getbuf ();
    201 q = *b;
    212 R = anotherfunction (b);
    213-2003 /* we want to use 'q' and 'r' here */
    2000 char * getbuf ()
    2001 {
    2002 char buff [8];
    2003-2050 /* unspecified buff defined here */
    2051 return (char*) buff;
    2052 }

    1. What will be in variable 'q' after line 201 is executed? Under
    what conditions might this not be so?



    2. Is there an alternative, but equivalent, way to write line
    2000? If so, what is it?



    3. Is getbuf() a reasonable function?



    4. Will getbuf() execute at all?



    5. Please comment on line 2051.



    6. Is getbuf() good practice, and why?



    7. What line not given should be provided for compilation?



    8. How, exactly, could one get a second 'char*' to use back from
    this function? Be specific in terms of the exact syntax needed. (That
    is, provide code.) Another way to state this question is how can this
    function be modified to return a 'char*' (that is, it maintains the
    same return type) from the function, and an additional 'char *' value
    in one function call. Please make sure that your answer will work even
    if the size of the char * desired is not known in the outside calling
    function. Avoid (do no use) C++ syntax. Include statement in called and
    calling functions. Use food programming practice.



    9. For those candidates who know SQL: There is a table with
    gene_ids ('gid') and clone_ids ('cid'). Each gene only resides on a
    single clone and each clone may contain multiple genes. How do would
    you find how many genes are on each and every clone? Please provide the
    SQL.



    10. What's the difference between system calls and library functions?
     
    , Oct 3, 2005
    #1
    1. Advertising

  2. Skarmander Guest

    wrote:
    > Know the answers to the following?
    >

    <snip>
    Yes. Except 5, since that's not a question.

    Do you? If not, better study harder.

    I will say the questions provided are pretty stupid. I'd think twice
    before going to work or study at a place giving such examinations.

    S.
     
    Skarmander, Oct 3, 2005
    #2
    1. Advertising

  3. John Bode Guest

    wrote:
    [obvious homework questions snipped]

    In the future, if you want help with your homework, it would be best
    not to cut and paste the assignment verbatim, and you should have at
    least *tried* to answer the questions on your own.

    If you do not understand any of the questions, or if you would like us
    to comment on your answers, feel free to ask for help. But do not
    expect us to do your homework for you.
     
    John Bode, Oct 3, 2005
    #3
  4. Randy Howard Guest

    wrote
    (in article
    <>):

    > Know the answers to the following?


    Do your own homework. Have you no shame?



    --
    Randy Howard (2reply remove FOOBAR)
     
    Randy Howard, Oct 3, 2005
    #4
  5. wrote:
    > Know the answers to the following?
    >
    > Line Contains
    >
    > 50 char *b, q, *r;
    > 200 b = getbuf ();
    > 201 q = *b;
    > 212 R = anotherfunction (b);
    > 213-2003 /* we want to use 'q' and 'r' here */
    > 2000 char * getbuf ()
    > 2001 {
    > 2002 char buff [8];
    > 2003-2050 /* unspecified buff defined here */
    > 2051 return (char*) buff;
    > 2052 }
    >
    > 1. What will be in variable 'q' after line 201 is executed? Under
    > what conditions might this not be so?


    <snip>

    If you really posted your homework verbatim, then I think the setter
    should fail the exam.


    --
    Nick Keighley

    "To every complex problem there is a simple solution...
    and it is wrong"
    -- Turski
     
    Nick Keighley, Oct 3, 2005
    #5
  6. Skarmander Guest

    Nick Keighley wrote:
    > wrote:
    >
    >>Know the answers to the following?
    >>
    >>Line Contains
    >>
    >>50 char *b, q, *r;
    >>200 b = getbuf ();
    >>201 q = *b;
    >>212 R = anotherfunction (b);
    >>213-2003 /* we want to use 'q' and 'r' here */
    >>2000 char * getbuf ()
    >>2001 {
    >>2002 char buff [8];
    >>2003-2050 /* unspecified buff defined here */
    >>2051 return (char*) buff;
    >>2052 }
    >>
    >>1. What will be in variable 'q' after line 201 is executed? Under
    >>what conditions might this not be so?

    >
    >
    > <snip>
    >
    > If you really posted your homework verbatim, then I think the setter
    > should fail the exam.
    >

    The answer, of course, being "nasal demons, unless hell has frozen over
    and they're all at the ice rink".

    Alternatively, "it's not line 201 that should be executed, it's you, and
    your compiler has the right to do so".

    S.
     
    Skarmander, Oct 3, 2005
    #6
  7. Eric Sosman Guest

    wrote On 10/03/05 16:15,:
    > Know the answers to the following?


    Yes.

    > Line Contains
    >
    > 50 char *b, q, *r;
    > 200 b = getbuf ();
    > 201 q = *b;
    > 212 R = anotherfunction (b);
    > 213-2003 /* we want to use 'q' and 'r' here */
    > 2000 char * getbuf ()
    > 2001 {
    > 2002 char buff [8];
    > 2003-2050 /* unspecified buff defined here */
    > 2051 return (char*) buff;
    > 2052 }
    >
    > 1. What will be in variable 'q' after line 201 is executed? Under
    > what conditions might this not be so?


    1a: Line 201 will not be executed. 1b: Because of
    (1a), "under all conditions" it is meaningless to speak
    of the value of `q'.

    > 2. Is there an alternative, but equivalent, way to write line
    > 2000? If so, what is it?


    2a: Yes. 2b: The words "is it" betray a lack of
    understanding of C, and should be replaced by "are they."

    > 3. Is getbuf() a reasonable function?


    No. C has no notion of "reason" or "reasonable" or
    "reasonability."

    > 4. Will getbuf() execute at all?


    No.

    > 5. Please comment on line 2051.


    It's shorter than "War and Peace."

    > 6. Is getbuf() good practice, and why?


    6a: No. 6b: Because it's bad practice.

    > 7. What line not given should be provided for compilation?


    Once again, the use of the singular instead of the
    plural shows that the questioner doesn't know C. Alternate
    answer: "cc filename.c".

    > 8. How, exactly, could one get a second 'char*' to use back from
    > this function? Be specific in terms of the exact syntax needed. (That
    > is, provide code.) Another way to state this question is how can this
    > function be modified to return a 'char*' (that is, it maintains the
    > same return type) from the function, and an additional 'char *' value
    > in one function call. Please make sure that your answer will work even
    > if the size of the char * desired is not known in the outside calling
    > function. Avoid (do no use) C++ syntax. Include statement in called and
    > calling functions. Use food programming practice.


    Which function? Also, how can the size of a `char*' be
    unknown, anywhere, since it's always `sizeof(char*)'? Finally,
    how hungry was the person who wrote the question?

    > 9. For those candidates who know SQL: There is a table with
    > gene_ids ('gid') and clone_ids ('cid'). Each gene only resides on a
    > single clone and each clone may contain multiple genes. How do would
    > you find how many genes are on each and every clone? Please provide the
    > SQL.


    Off-topic.

    > 10. What's the difference between system calls and library functions?


    Library functions exist, system calls do not.

    --
     
    Eric Sosman, Oct 3, 2005
    #7
  8. Guest

    schreef:

    > Know the answers to the following?


    Ok. I'll play...

    <snip all my answers>

    Ok. i played. It was simple. It was simple, too, to realize i'm doing
    your homework.
     
    , Oct 4, 2005
    #8
  9. Guest

    Here is my answer is that correct?
    1. What will be in variable 'q' after line 201 is executed? Under what
    conditions might this not be so?



    aln >> content of b, of which is probably garbage. under some weird
    circumstances (eg, snippit within a func that doesn't do garbage
    collection and loops around) b might be last known value. if this was
    java, i think b might get init to null automagically.



    2. Is there an alternative, but equivalent, way to write line 2000? If
    so, what is it?



    aln >> int get_string(char *buff)



    3. Is getbuf() a reasonable function?



    aln >> i think so but the answer is probably not because of something
    to do with a non-static array being casted as a string ptr, right?



    4. Will getbuf() execute at all?



    aln >> probably not; intuition not based on logical understanding of c
    but on "feel" of questions from 3) thru 6).



    5. Please comment on line 2051.



    aln >> casting to char * for local array probably wont show anything at
    all; content only avail w/in scope of func, right?



    6. Is getbuf() good practice, and why?



    aln >> see 5) above.



    7. What line not given should be provided for compilation?



    aln >> dont know.



    8. How, exactly, could one get a second 'char*' to use back from this
    function? Be specific in terms of the exact syntax needed. (That is,
    provide code.) Another way to state this question is how can this
    function be modified to return a 'char*' (that is, it maintains the
    same return type) from the function, and an additional 'char *' value
    in one function call. Please make sure that your answer will work even
    if the size of the char * desired is not known in the outside calling
    function. Avoid (do no use) C++ syntax. Include statement in called and
    calling functions. Use good programming practice.



    aln >> no idea...



    9. For those candidates who know SQL: There is a table with gene_ids
    ('gid') and clone_ids ('cid'). Each gene only resides on a single clone
    and each clone may contain multiple genes. How do would you find how
    many genes are on each and every clone? Please provide the SQL.



    aln >> yikes i dont remember anything i learned (and haven't used in) 6
    years ago!!!



    10. What's the difference between system calls and library functions?



    aln >> 1st attempt a: system calls is invoked at runtime when applic
    func is called. library functions are incorp into object as defined and
    referenced func calls and ck'ed at compile time; ie, lib functions
    exists in object code, whereas sys calls are (may be?) undefined?

    2nd attempt b: sys call affects os (eg, lo level kernel stuff routines)
    whereas lib func may act as liason between app and sys call else just
    another func call to existing library of common routines. eg printf is
    libr func and the content of printf has sys calls...
     
    , Oct 5, 2005
    #9
  10. RecruitC++ Guest

    Greetings,
    I am the hiring manager for the C assessment that you so bold
    displayed on the internet and FYI I will be removing your candidac
    from our application process as you are obviously not qualified fo
    this position as you are unable to answer questions by yourself. Mora
    of the story...remember you're using the INTERNET DUH!:

    --
    RecruitC++Message posted via http://www.exforsys.com for all your training needs
     
    RecruitC++, Oct 12, 2005
    #10
  11. appletree Guest

    hi there, if u have the answers for those questions would u mind to
    share with me, i have my, and not sure if they are right, so msg me if
    u want see my answers.
    wrote:
    > Know the answers to the following?
    >
    > Line Contains
    >
    > 50 char *b, q, *r;
    > 200 b = getbuf ();
    > 201 q = *b;
    > 212 R = anotherfunction (b);
    > 213-2003 /* we want to use 'q' and 'r' here */
    > 2000 char * getbuf ()
    > 2001 {
    > 2002 char buff [8];
    > 2003-2050 /* unspecified buff defined here */
    > 2051 return (char*) buff;
    > 2052 }
    >
    > 1. What will be in variable 'q' after line 201 is executed? Under
    > what conditions might this not be so?
    >
    >
    >
    > 2. Is there an alternative, but equivalent, way to write line
    > 2000? If so, what is it?
    >
    >
    >
    > 3. Is getbuf() a reasonable function?
    >
    >
    >
    > 4. Will getbuf() execute at all?
    >
    >
    >
    > 5. Please comment on line 2051.
    >
    >
    >
    > 6. Is getbuf() good practice, and why?
    >
    >
    >
    > 7. What line not given should be provided for compilation?
    >
    >
    >
    > 8. How, exactly, could one get a second 'char*' to use back from
    > this function? Be specific in terms of the exact syntax needed. (That
    > is, provide code.) Another way to state this question is how can this
    > function be modified to return a 'char*' (that is, it maintains the
    > same return type) from the function, and an additional 'char *' value
    > in one function call. Please make sure that your answer will work even
    > if the size of the char * desired is not known in the outside calling
    > function. Avoid (do no use) C++ syntax. Include statement in called and
    > calling functions. Use food programming practice.
    >
    >
    >
    > 9. For those candidates who know SQL: There is a table with
    > gene_ids ('gid') and clone_ids ('cid'). Each gene only resides on a
    > single clone and each clone may contain multiple genes. How do would
    > you find how many genes are on each and every clone? Please provide the
    > SQL.
    >
    >
    >
    > 10. What's the difference between system calls and library functions?
     
    appletree, Oct 19, 2005
    #11
  12. wrote:

    <snip>

    > Use food programming practice.



    /* Example of poor food programming */
    char izo_burrito, and_a;
    double tequila, please;
    (void) bowels();


    Is that the right answer? What did I win?


    Mark F. Haigh
     
    Mark F. Haigh, Oct 19, 2005
    #12
  13. Richard Tobin, Oct 19, 2005
    #13
  14. "appletree" <> writes:
    > hi there, if u have the answers for those questions would u mind to
    > share with me, i have my, and not sure if they are right, so msg me if
    > u want see my answers.
    > wrote:
    >> Know the answers to the following?
    >>
    >> Line Contains
    >>
    >> 50 char *b, q, *r;
    >> 200 b = getbuf ();
    >> 201 q = *b;
    >> 212 R = anotherfunction (b);
    >> 213-2003 /* we want to use 'q' and 'r' here */
    >> 2000 char * getbuf ()
    >> 2001 {
    >> 2002 char buff [8];
    >> 2003-2050 /* unspecified buff defined here */
    >> 2051 return (char*) buff;
    >> 2052 }
    >>
    >> 1. What will be in variable 'q' after line 201 is executed?


    Bits.

    >> what conditions might this not be so?


    If the program is run on a trinary computer.

    >> 2. Is there an alternative, but equivalent, way to write line
    >> 2000?


    Yes.

    >> If so, what is it?


    "line MM"

    >> 3. Is getbuf() a reasonable function?


    It's eminently reasonable; after all, it has no arguments.

    >> 4. Will getbuf() execute at all?


    Never. It's morally opposed to the death penalty. (This is a trick
    question; if you haven't met getbuf() personally, you probably won't
    know this.)


    >> 5. Please comment on line 2051.


    I really like the monospaced font.

    >> 6. Is getbuf() good practice, and why?


    It's undoubtedly good practice for something.

    >> 7. What line not given should be provided for compilation?


    "Hey, baby, do you compile around here often?"

    >> 8. How, exactly, could one get a second 'char*' to use back from
    >> this function? Be specific in terms of the exact syntax needed. (That
    >> is, provide code.) Another way to state this question is how can this
    >> function be modified to return a 'char*' (that is, it maintains the
    >> same return type) from the function, and an additional 'char *' value
    >> in one function call. Please make sure that your answer will work even
    >> if the size of the char * desired is not known in the outside calling
    >> function. Avoid (do no use) C++ syntax. Include statement in called and
    >> calling functions. Use food programming practice.


    return (char*) buff + 'char*'; /* with a side order of onion rings */

    >> 9. For those candidates who know SQL: There is a table with
    >> gene_ids ('gid') and clone_ids ('cid'). Each gene only resides on a
    >> single clone and each clone may contain multiple genes. How do would
    >> you find how many genes are on each and every clone? Please provide the
    >> SQL.


    SQL://ACACACATCAGCATATCCAACACAAGAATTGGGCACACGTAA/

    >> 10. What's the difference between system calls and library functions?


    3.7 microseconds. Less on newer CPUs.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Oct 19, 2005
    #14
  15. Mabden Guest

    "Keith Thompson" <> wrote in message
    news:...
    > >> 3. Is getbuf() a reasonable function?

    >
    > It's eminently reasonable; after all, it has no arguments.


    Keith! Actual humor?! Next you'll be spouting Zen! ;-)

    --
    Mabden
     
    Mabden, Oct 26, 2005
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. maadhuu

    want to know hoe the following works .

    maadhuu, Aug 13, 2005, in forum: C Programming
    Replies:
    4
    Views:
    425
    Michael Mair
    Aug 13, 2005
  2. nambi
    Replies:
    0
    Views:
    278
    nambi
    Nov 19, 2007
  3. amit129
    Replies:
    2
    Views:
    232
    Szabolcs Borsanyi
    May 27, 2008
  4. amit129
    Replies:
    0
    Views:
    260
    amit129
    May 27, 2008
  5. Andries

    I know, I know, I don't know

    Andries, Apr 23, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    262
    Gregory Toomey
    Apr 23, 2004
Loading...

Share This Page