Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different ways to initialize variables

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;

?

like image 226
user2975699 Avatar asked Mar 20 '14 20:03

user2975699


People also ask

What are the two ways of initializing variables?

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.

What are the two ways of initializing variables in Java?

Java offers two types of initializers, static and instance initializers.

What are initializing variables?

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.


1 Answers

You can use:

int z;
z = 3;

Or just:

int z = 3;

Or:

int z(3);

Or:

int z = int(3);
like image 150
PaulG Avatar answered Sep 28 '22 07:09

PaulG