简体   繁体   中英

What is the meaning of "res" in C++?

I've tried Googling and actually searching this website for a concise answer on this and so far I have been unable to find some help, I believe it might be because the answer is too simple.

I have just started uni and we have some exercises to resolve. In one of them I am presented with the following:

float avge(int a, int b, int c) {
  float res;
  res = (a + b + c) / 3.0;
  return res;
}

int main() {
  int n1, n2, n3;
  float m;
  cin >> n1;
  cin >> n2;
  cin >> n3;
  m = avge(n1, n2, n3);
  cout << m << endl;
  return 0;
}

It works as intended but I can't understand what res does for the code. Could someone explain it to me?

res is the name of a local variable in the function avge that is returned at then end of that function.

// Variable of type float with name "res" is declared
float res;

// Compute some value and assign it to this variable
res = (a+b+c)/3.0;

// Return the variable to the caller
return res;

"res" usually is an abbreviation for "result".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM