开发者

Would the initialization value be computed at compile time or runtime?

开发者 https://www.devze.com 2023-03-27 11:41 出处:网络
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?

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 initializatio开发者_开发问答n 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?


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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号