Debug 2!

Sharky Forums


Results 1 to 13 of 13

Thread: Debug 2!

  1. #1
    Katana Wielding Moderator Klashe's Avatar
    Join Date
    Sep 2000
    Location
    IL, USA
    Posts
    3,306

    Post Debug 2!

    Hey all, this isn't really a debug question, but it's in the same vein.

    You know 'em, you love 'em. They are pointers. See if you can answer these simple questions about 'em:

    Based on the following declarations:
    int i=3;
    int j=5;
    int *p = &i;
    int *q = &j;

    determine the values for each of the following expressions. Consider each expression independent.

    A) p==&i

    B) * (* (& p ))

    C) ((7 * (* p)) / (* q)) + 7

    D) ((7 * (* p)))/*q+7

    One answer per person please!

    ------------------
    If I rest, then I rust.
    --Indian Proverb

  2. #2
    Expensive Sushi
    Join Date
    Jan 2001
    Location
    Plainfield, IL. USA
    Posts
    12

    Post

    I hate pointers...besides, shouldn't you be working?

    Originally posted by Klashe:
    Hey all, this isn't really a debug question, but it's in the same vein.

    You know 'em, you love 'em. They are pointers. See if you can answer these simple questions about 'em:

    Based on the following declarations:
    int i=3;
    int j=5;
    int *p = &i;
    int *q = &j;

    determine the values for each of the following expressions. Consider each expression independent.

    A) p==&i

    B) * (* (& p ))

    C) ((7 * (* p)) / (* q)) + 7

    D) ((7 * (* p)))/*q+7

    One answer per person please!


  3. #3
    Ursus Arctos Moderatis Grizzly's Avatar
    Join Date
    Sep 2000
    Location
    Providence, RI USA
    Posts
    3,077

    Post

    Alright, Im not entirely confident about these but here's my shot:

    A) p==&i
    ---------answer: value in P is the "address" (memory location) of i. THe exact value could be anything.

    B) * (* (& p ))
    --------answer: 3

    C) ((7 * (* p)) / (* q)) + 7
    --------answer: 11

    D) ((7 * (* p)))/*q+7
    --------answer: 1


    Am I wrong? Am I wrong? Am I wrong?

  4. #4
    Katana Wielding Moderator Klashe's Avatar
    Join Date
    Sep 2000
    Location
    IL, USA
    Posts
    3,306

    Post

    Originally posted by Grizzly:
    Alright, Im not entirely confident about these but here's my shot:

    A) p==&i
    ---------answer: value in P is the "address" (memory location) of i. THe exact value could be anything.

    Am I wrong? Am I wrong? Am I wrong?
    I'll just answer A for you. We'll let other people answer the other three.

    Yes, you are wrong. You are not reading the question correctly. I knew this would throw some people off. Maybe I should rewrite it:

    p == &i

    ------------------
    If I rest, then I rust.
    --Indian Proverb

  5. #5
    Ursus Arctos Moderatis Grizzly's Avatar
    Join Date
    Sep 2000
    Location
    Providence, RI USA
    Posts
    3,077

    Post

    Originally posted by Klashe:
    I'll just answer A for you. We'll let other people answer the other three.

    Yes, you are wrong. You are not reading the question correctly. I knew this would throw some people off. Maybe I should rewrite it:

    p == &i


    Ooooh my fault! That was a test for equality, not an assignment operator. Answer is '1', or 'true'.


  6. #6
    Katana Wielding Moderator Klashe's Avatar
    Join Date
    Sep 2000
    Location
    IL, USA
    Posts
    3,306

    Post

    Originally posted by Grizzly:

    Ooooh my fault! That was a test for equality, not an assignment operator. Answer is '1', or 'true'.


    There you go!


    ------------------
    If I rest, then I rust.
    --Indian Proverb

  7. #7
    Ursus Arctos Moderatis Grizzly's Avatar
    Join Date
    Sep 2000
    Location
    Providence, RI USA
    Posts
    3,077

    Post

    Originally posted by Klashe:

    There you go!


    Was I correct on the rest of the answers?


  8. #8
    Katana Wielding Moderator Klashe's Avatar
    Join Date
    Sep 2000
    Location
    IL, USA
    Posts
    3,306

    Post

    Originally posted by Grizzly:
    Was I correct on the rest of the answers?

    Well, since no one else in answering, I'll give you the rest of the answers.

    B) correct. when a & and a * are coupled together they are complimentary so they cancel each other out. so essiantially the question is *p which just accesses the value of &i which is 3.
    C) correct

    D)incorrect. kind of a trick question. Look at it carefully. (Hint: pay attention to the spaces! )

    ------------------
    If I rest, then I rust.
    --Indian Proverb

  9. #9
    Ursus Arctos Moderatis Grizzly's Avatar
    Join Date
    Sep 2000
    Location
    Providence, RI USA
    Posts
    3,077

    Post

    Originally posted by Klashe:
    Well, since no one else in answering, I'll give you the rest of the answers.

    B) correct. when a & and a * are coupled together they are complimentary so they cancel each other out. so essiantially the question is *p which just accesses the value of &i which is 3.
    C) correct

    D)incorrect. kind of a trick question. Look at it carefully. (Hint: pay attention to the spaces! )

    Ooooh, actually isn't the answer to C & D the same? 11 ?


  10. #10
    Mako Shark
    Join Date
    Sep 2000
    Posts
    3,518

    Post

    ugh, reminds me of school. I try to stay away from those types of things. I havent seen that since my first few CS classes.

    ------------------
    "You know, I have one simple request, and that is to have sharks with frickin laser beams attached to their heads. Is that too much to ask?"
    Icna tpye 300 wrdos per mnieut

  11. #11
    Katana Wielding Moderator Klashe's Avatar
    Join Date
    Sep 2000
    Location
    IL, USA
    Posts
    3,306

    Post

    Originally posted by Grizzly:
    Ooooh, actually isn't the answer to C & D the same? 11 ?

    Nope, look at it closer. What does /* represent in C?

    ------------------
    If I rest, then I rust.
    --Indian Proverb

  12. #12
    Katana Wielding Moderator Klashe's Avatar
    Join Date
    Sep 2000
    Location
    IL, USA
    Posts
    3,306

    Post

    Originally posted by Sol:
    ugh, reminds me of school. I try to stay away from those types of things. I havent seen that since my first few CS classes.

    Yeah, I know. But we got to get some kind of programming questions out in this forum!

    ------------------
    If I rest, then I rust.
    --Indian Proverb

  13. #13
    Ursus Arctos Moderatis Grizzly's Avatar
    Join Date
    Sep 2000
    Location
    Providence, RI USA
    Posts
    3,077

    Post

    Originally posted by Klashe:
    Nope, look at it closer. What does /* represent in C?


    OH GOD!!! I can't believe I missed that one!! hahahahah, that's a *damn* good one Klashe! Friggin comments!

    [This message has been edited by Grizzly (edited January 17, 2001).]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •