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

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -