A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

Curry

  • one year ago

How does the following pointer diagram work out in C?

  • This Question is Closed
  1. Curry
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    2 Attachments
  2. Curry
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Given the data shown above from a 16-bit system, with integer x, unsigned integer y, and integer z, what will the following code snippet print out?

  3. Curry
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    @oldrin.bataku

  4. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    int *p = &x; /* p points to the value 0x0000 at 0x0002 */ printf("%d\n", *p); /* print the value p points to (0) */ p++; /* p now points to the address 0x0004 since sizeof(int) = 2 here */ x = (int) p; /* now x's value is that address, 0x0004 */ printf("%d\n", x); /* print the value of x (0x0004) */ printf("%d\n", *p); /* p still points to the value in y at 0x0004, which is 0x0005 */ printf("%d\n", *(&(*p))); /* *p is an alias for y, so &(*p) is equivalent to p, and then *(&(*p)) gives the value in y, which is still 0x0005 */ printf("%d\n", *(p-1) + 1); /* so p-1 gives the address 0x0002 again, so p-1 points to x, meaning *(p-1) gives the value in x (0x0004) and then +1 gives 0x0005 */

  5. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.