Home > Mobile >  Cant understand why im getting this warning
Cant understand why im getting this warning

Time:11-18

double S = 0;
    double *pSum = &S;

    double P = 0;
    double *pAverage = &P;

    printf("The average and sum of the variables: %lf %lf", &S, &P);

im working with pointers and functions but for some reason i cant understand why im getting 2 warning specifically

non-float passed as argument '3' when float is required in call to 'printf' actual type: 'double *'. non-float passed as argument '2' when float is required in call to 'printf' actual type: 'double *'.

to be completely honest i dont know what to try to get rid of the warning

CodePudding user response:

It seems you have mixed arguments for scanf (where you need to pass pointers to the variables) and printf (which want values, not pointers).

The correct solution is to not use the pointer-to operator &:

printf("The average and sum of the variables: %lf %lf", S, P);

CodePudding user response:

You can use

printf("The average and sum of the variables: %lf %lf", S, P);

to get the values from the varriables directly or to use:

printf("The average and sum of the variables: %lf %lf", *pSum, *pAverage);

to get the value from the pointers= * before a pointer means "Give me the value of that pointer"

  • Related