Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi I need some help would appreciate any help that you can give me. I need some

ID: 3642162 • Letter: H

Question

Hi I need some help would appreciate any help that you can give me. I need some help on the how the pointers would look for this assignment. I have some difficulty understanding pointers. Please explain in the simplest way that you can because I am still pretty new to programming. Thanks!

Write a function that accepts three floating point values as parameters and sorts them from largest to smallest. The program must use pointers or references and the function will affect (sort) the three variables entered by the user in the calling program (main).

Explanation / Answer

Okay, so the first thing about pointers. You have to know that variables get assigned to a spot in memory. That memory has what is called an address. So it's kind of like a mailbox in a way. Your mailbox has a number, and you put stuff in it. So when you want to find out the number of the mailbox you have to "reference" it. It works the same way in C. variable = 10; //I'm placing 10 in the mailbox. address = &variable //This says, go to the mailbox and instead of looking at 10, check the address A pointer works just the same. Except that when you say "this is a pointer". You are telling it "hey what I'm giving you is not just data, it's an address!". For example get_addr = address //This copies the address of variable (the mailbox number) get_val = *address //This says "oh, here's an address" and instead gets a value inside of the memory location. get_val will now equal 10. I hope this helps you understand a little more. Please read http://www.cplusplus.com/doc/tutorial/pointers/