Wednesday, June 27, 2018

How do you initialize a variable in C++?

Let us say we are trying to initilaize a variable of type integer, iX. There are three ways you can initialize a variable.

We use the following statement to initialize:

int iX = 100;  This is the syntax for copy initialization.

This is called copy initialization saying that intX's value is 5.

In direct initiization you use the statement:

int iX(100);  This is the syntax for direct initialization but should not be confused with a function.

There is yet another kind of initialization stated this way:

This is called Uniform initizlization used most of the data types.
int  ix{100};

Review the following initialize.cpp file.

The file was created using a Blank C++ project in Visual Studio Community 2017 Version 15.5.7



No comments: