Question

(C++)Declare a pointer variable bookPtr and initialize it with the address of myBook. Use the structure...

(C++)Declare a pointer variable bookPtr and initialize it with the address of myBook. Use the structure pointer operator (->) to change the price of myBook to $100. Thank you :)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C CODE :

#include <stdio.h>
struct book // structure book
{
int price; // price of the book
};

int main()
{
struct book *bookPtr, myBook;
bookPtr = &myBook; // store address of myBook in bookPtr

bookPtr -> price = 100; // change the price in myBook using bookPtr
  
printf("Book Price = $%d", bookPtr -> price); // prints book price

return 0;
}

OUTPUT :

Book Price = $100 .. Program finished with exit code 0 Press ENTER to exit console.

Add a comment
Know the answer?
Add Answer to:
(C++)Declare a pointer variable bookPtr and initialize it with the address of myBook. Use the structure...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT