开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜