scanf - Pass a variable directly into a function in C? -


as example assume have function double calculate(double input); takes input , adds 5.0 it, returns value.

say wanted take user input. okay create variable use scanf, call double temp. scanf("%lf", &temp); , use function calculate(temp).

is there way pass input directly function calculate without having setup variable in middle?

it isn't possible scanf() because function designed parse input in format choose, have assign multiple input values in 1 call. note wouldn't change compiled code anyway because, whether create variable or not, real machine has store value somewhere passing function.

if care instead shape of c code, can of course provide own input function does return input, e.g.

double getdoubleinput(void) {     double in;      /* add sanity checks , whatever, following stub ... */     scanf("%lf", &in);     return in; } 

and use instead. compiler inline if appropriate, generated code should stay same.


Comments

Popular posts from this blog

html - Difficulties with background-image property -

visual studio code - What does the isShellCommand property actually do and how should you use it? -

ios - Segue not passing data between ViewControllers -