5

if i have a function that uses the rand() function as its initialization value, would that value be found when the program compiles, or when the function is run?

say:

int function(int init = rand()){
  return init;
}

if it is found at compile time, how can i get the initialization to be dynamic? i guess i would use NULL as the initialization value, but how would i tell the difference between NULL and init = 0?

jruizaranguren
  • 12,679
  • 7
  • 55
  • 73
marg
  • 51
  • 1

1 Answers1

6

The value is calculated in runtime.

You can always create a tiny program and check that on practice:

int main() {
    srand( time(NULL) );
    std::cout << function() << std::endl;
}
eugene_che
  • 1,997
  • 12
  • 12