Question

a 14. Suppose a pointer to a structure, bookPte, is defined. This structure also contains member, price that is a pointer to a double. Provide the equivalent to bookPtr price?
0 0
Add a comment Improve this question Transcribed image text
Answer #1

equivalent to *bookptr->price is (*bookptr).price)

//below demonstrated the same

#include<stdio.h>

//book struct is defined

typedef struct book

{

double price;

};

int main()

{

//created book structure

struct book *bookptr=(struct book*)malloc(sizeof(struct book)*1);

//printing the data

printf("%d\n",bookptr->price);

//using another way to print from struct pointer

printf("%d",(*bookptr).price);

return 0;

}

//compiling and running the code (some garbage value will print as not initialized the price value)

printed by *bookptr->price 7428816 printed by (bookptr).price) 7428816 Process exited after 0.2549 seconds with return value

Please do let me know if u have any doubts..

Add a comment
Know the answer?
Add Answer to:
Suppose a pointer to a structure, bookPtr is defined. This structure also contains a member, price...
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