Ask your own question, for FREE!
Computer Science 5 Online
OpenStudy (anonymous):

Please help! Programming in C code: Write a function called doubler that is passed the address of a floating-point variable and doubles the value of that original variable. Confirm that the original was doubled by printing its value before and after calling doubler.

hartnn (hartnn):

what have you tried?? you'll need a float variable : `float var = 0;` `&var` will give you the address of the memory location where this variable is stored. when the function call to 'doubler' is made, we pass this address: &var. >> This is called 'pass by reference', where we pass the memory address of the variable. `float answer = doubler(&var);` so your double function definition would look something like this: `float doubler(float* arg)` `{` ` return (*arg)*2; //` `}` the address of var, is caught in pointer arg. *arg will give the `value` pointed out by arg. (*arg)*2 will give the required result which we pass back and will be cause in the float variable 'answer' which you can print. Give it a try! ask doubts :)

hartnn (hartnn):

will be caught** in the float variable

OpenStudy (rsmith6559):

Actually, wouldn't it be: void doubler( float* arg ) { *arg *= 2; }

OpenStudy (anonymous):

@rsmith6559 is correct.

hartnn (hartnn):

oh yeah, we've passed by reference, so we also don't need to catch anything

jaynator495 (jaynator495):

Hartnn.. you... you code? *mouth drops*

hartnn (hartnn):

LOL Jay, I code for living :P

jaynator495 (jaynator495):

WHY DIDNT I KNOW THIS! XD

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Latest Questions
Mari103: How to pop out like a Jacc In the box
7 hours ago 0 Replies 0 Medals
Breathless: Spooky witch but cute
14 hours ago 3 Replies 0 Medals
Arriyanalol: help
14 hours ago 10 Replies 2 Medals
Arriyanalol: @tinydinoUwU stop trying to find a argument u blad lil boy
1 day ago 5 Replies 4 Medals
Jaded012023: Please tell me what you all think of this song
17 hours ago 6 Replies 1 Medal
Arriyanalol: bro how
17 hours ago 2 Replies 3 Medals
Arriyanalol: cant wait for the new bluey movie in 2027
1 day ago 12 Replies 2 Medals
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!