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.
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 :)
will be caught** in the float variable
Actually, wouldn't it be: void doubler( float* arg ) { *arg *= 2; }
@rsmith6559 is correct.
oh yeah, we've passed by reference, so we also don't need to catch anything
Hartnn.. you... you code? *mouth drops*
LOL Jay, I code for living :P
WHY DIDNT I KNOW THIS! XD
Join our real-time social learning platform and learn together with your friends!