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
?
CompileTime - The generated code uses compile-time initialization for relations, flow ports, framework data, and all user-defined attributes. RunTime - The generated code uses runtime initialization for relations, flow ports, framework data, and all user-defined attributes.
Compile time is the period when the programming code (such as C#, Java, C, Python) is converted to the machine code (i.e. binary code). Runtime is the period of time when a program is running and generally occurs after compile time.
Compile-time is the time at which the source code is converted into an executable code while the run time is the time at which the executable code is started running.
Syntax: type array_name[size] = { list_of_values }; //integer array initialization int marks[4]={ 67, 87, 56, 77 }; //float array initialization float area[3]={ 23.4, 6.8, 5.5 }; //character array initialization char name[12]={ 'T', 'u', 't', 'o', 'r', 'i', 'a', 'l', 'i', 'n', 'k', '\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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With