There are different ways to initialize a variable in c++.
int z(3)
is same as int z=3
.
Is
int z;
z(3);
same as
int z;
z=3;
?
Two types of variable initialization exist: explicit and implicit. Variables are explicitly initialized if they are assigned a value in the declaration statement. Implicit initialization occurs when variables are assigned a value during processing.
Java offers two types of initializers, static and instance initializers.
Initializing a variable means specifying an initial value to assign to it (i.e., before it is used at all). Notice that a variable that is not initialized does not have a defined value, hence it cannot be used until it is assigned such a value.
You can use:
int z;
z = 3;
Or just:
int z = 3;
Or:
int z(3);
Or:
int z = int(3);
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