Initialize Variables within if and switch Statements

Learn to initialize variables within if and switch statements.

We'll cover the following

Beginning with C++17, if and switch now have initialization syntax, much like the for loop has had since C99. This allows we to limit the scope of variables used within the condition.

How to do it

You may be accustomed to code like this:

Get hands-on with 1200+ tech skills courses.