vendredi 24 avril 2015

which will the best way to use the result of function between assigning it to a variable or calling the function again and again?

I have a function which will return a value, i want to use the result of the function in multiple places. Storing the result to a variable and use it where ever i want or directly call the function again and again instead of storing it in a variable and using that.

#include<iostream>

int function(int x,int y){
  return (x<<y);
}

int main(){
  int a = 10;
  int b = 5;
  int c = function(a,b);
  int d = c*c; 
  int e =function(a,b)*function(a,b);
  return 0;
}

Aucun commentaire:

Enregistrer un commentaire