Question

Consider two possible functions for adding together two xyz points: struct point add_points(struct point p1, struct...

Consider two possible functions for adding together two xyz points:

struct point add_points(struct point p1, struct point p2)
struct point* add_points(struct point* p1, struct point* p2)

Which of these functions should we expect to operate more efficiently and why?

Consider two possible functions for adding together two xyz points: struct point add_points(struct point p1, struct point p2) struct point* add_points(struct point* p1, struct point* p2) Which of these functions should we expect to operate more efficiently and why?

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

struct point add_points(struct point p1, struct point p2)

  • p1 and p2 are normal variables
  • The return value is also normal value.

struct point* add_points(struct point* p1, struct point* p2)

  • p1 and p2 are pointer variables
  • The return value is also pointer value.

struct point* add_points(struct point* p1, struct point* p2) is more powerful than the struct point add_points(struct point p1, struct point p2).

Reason :

  • Generally pointers are more faster access and operate than the normal variable.
  • Similarly structure pointer variables are more powerful than the structure variables.
  • Structure pointer variables are directly operate with the address location so its more effecient and faster.
  • Using structure pointers saves memory because calling function variables and called function variables share the memory where as normal structure functions memory allocated is different for calling function variables and called function variables.

Therefore we can justify that struct point* add_points(struct point* p1, struct point* p2) is more powerful than the struct point add_points(struct point p1, struct point p2).

Add a comment
Know the answer?
Add Answer to:
Consider two possible functions for adding together two xyz points: struct point add_points(struct point p1, struct...
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