Problem With Invalid Operands To Binary Expression C++, Invalid Operands To Binary Expression

Im working on a function that takes some values and finds the min, max, and average of the values. I”m passing everything to the function by reference and am getting some errors when I try and do basic operations like + and / Namely the error is

Invalid operands to binary expression (“double *” and “double *”)

void MinMaxAvg(double *pA, double *min, double *max, double *avg, int lines, double *total ){ for (int i=0; i max) { max = &pA; } } total += &pA; //



It seems like you”re getting some of the types confused there. In your example you”re setting the pointers to a new value, not the value of said pointers.

Đang xem: Invalid operands to binary expression c++

The first would have to be:

*total += pA;While the second should be:

*avg = (*total / lines);In fact, you probably want to use floating point division on the second error there (some compilers are notorious for using integer divison in unexpected places):

*avg = (*total / (double)lines);You”ll still be getting errors if you do it like that, however. For example &pA > … will result in a pointer comparison, i.e. the address of the pointers will be compared. Most likely not what you want.

answered Feb 7 “13 at 13:20


96044 silver badges1010 bronze badges
Add a comment |
You”re trying to add an address to a pointer, that”s not a valid operation.

You probably meant:

*total += pA;Your use of &pA seems very confused, as does the re-assignment of the pointers min and max.

If you have a pointer to a value (like double *min), then *min is how you access (read or write) the value being pointed at.

Read more: In Search Of The Excavation Team Vanilla Wow, In Search Of The Excavation Team

answered Feb 7 “13 at 13:16


363k6161 gold badges449449 silver badges577577 bronze badges
Add a comment |
There is no “pass by reference” in C language unlike C++. You should dereference each pointer in your code if you want work with variables values. Now you work with variables addresses.

edited Feb 7 “13 at 13:31
answered Feb 7 “13 at 13:21


47233 silver badges77 bronze badges
Add a comment |

Your Answer

Thanks for contributing an answer to Stack Overflow!

Please be sure to answer the question. Provide details and share your research!

But avoid

Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

Read more: wow frost mage pvp 6.2

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Facebook
Sign up using Email and Password

Post as a guest

Email Required, but never shown

Post as a guest


Required, but never shown

Post Your Answer Discard

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged c or ask your own question.

The Overflow Blog
Featured on Meta
I keep getting this error: invalid operands to binary ^ (have 'double' and 'double')
Error: Invalid operands to binary expression double double, but I'm not using pointers, only using ints
Void Factorial Using Pointers in C
invalid operands of types 'float()' and 'double' to binary 'operator
Invalid operands in sigmoid function
“Invalid Operands to Binary” error when trying to calculate square of elements in array
Hot Network Questions more hot questions

Question feed
Subscribe to RSS
Question feed To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Stack Overflow
Stack Exchange Network
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev2021.4.16.39093

Stack Overflow works best with JavaScript enabled


Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Leave a Comment