<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://wiki.planetchili.net/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Rudra</id>
		<title>Chilipedia - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="https://wiki.planetchili.net/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Rudra"/>
		<link rel="alternate" type="text/html" href="https://wiki.planetchili.net/index.php/Special:Contributions/Rudra"/>
		<updated>2026-06-13T06:30:26Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.26.3</generator>

	<entry>
		<id>https://wiki.planetchili.net/index.php?title=Constexpr&amp;diff=1512</id>
		<title>Constexpr</title>
		<link rel="alternate" type="text/html" href="https://wiki.planetchili.net/index.php?title=Constexpr&amp;diff=1512"/>
				<updated>2018-11-12T11:06:11Z</updated>
		
		<summary type="html">&lt;p&gt;Rudra: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;code&amp;gt;constexpr&amp;lt;/code&amp;gt; is a keyword applied to variables and functions. It's basically the same as the &amp;lt;code&amp;gt;[[http://wiki.planetchili.net/index.php?title=Const const]]&amp;lt;/code&amp;gt; keyword but enforces an additional rule that &amp;quot;The value of this const will be available at compile time&amp;quot; &lt;br /&gt;
&lt;br /&gt;
== Difference between const &amp;amp; constexpr ==&lt;br /&gt;
=== Basics ===&lt;br /&gt;
In C++ there can be 2 types of constants: &lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Whose value is known at compile time.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
const int x = 50;&lt;br /&gt;
const int z = x + 1; &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
During compile time, the compiler knows the value of x and z would be 50 and 51 respectively. And the values won’t change throughout the lifetime of the program. So it goes “I’ll just substitute all the references to x and z with 50 and 51, instead of looking up what the values of x and z every time during runtime”.&lt;br /&gt;
&lt;br /&gt;
This allows 50 and 51 to be used as literals (hardcoded values) with all their advantages and at the same time not clutter our code with random numbers that are hard to interpret the meaning of.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol start=&amp;quot;2&amp;quot; style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Whose value is not known at compile time.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;source&amp;gt;const int y = GenRandomNumber();&amp;lt;/source&amp;gt;&lt;br /&gt;
In this case the value of y would be impossible to determine at compile time as a we don’t know what random number would be generated at runtime.&lt;br /&gt;
&lt;br /&gt;
NOTE: the variable is still a constant, once a random number is assigned to it the value cannot change.&lt;br /&gt;
&lt;br /&gt;
When the compiler comes across scenario #1 it marks x an z as constant expressions i.e. their value can be evaluated at compile time and in scenario #2 marks y as being a constant but not a constant expression as it can only be evaluated during runtime.&lt;br /&gt;
&lt;br /&gt;
This can be a bit confusing in certain contexts e.g.&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
int anArray[x]; // Compiles successfully &lt;br /&gt;
int anotherArray[y]; // Fails compilation &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Certain operations require compile-time knowledge of a variable, in this case, anotherArray declaration would throw an error even though y is a const just like x. This is because the value of y cannot be computed until the function GenRandomNum() is run.&lt;br /&gt;
&lt;br /&gt;
Due to this confusion, it is hard to evaluate what constants will be available during compile time, and which won’t like in our example above. As your code base gets bigger this can spiral out of control, as multiple people are working on the same code base.&lt;br /&gt;
&lt;br /&gt;
This is where the keyword &amp;lt;code&amp;gt;constexpr&amp;lt;/code&amp;gt; comes in as it tells the compiler that the value of this variable should be deduced at compile time to allow for scenarios such as the one above. If y was declared as &amp;lt;code&amp;gt; constexpr int y = GetRandomNumber()&amp;lt;/code&amp;gt; the compiler would throw an error that the value cannot be evaluated at compile time. It clarifies the intended use of the variable.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
constexpr int y = GetRandomNumber(); // error&lt;br /&gt;
constexpr int y = 69; // Compiles fine&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Advanced ==&lt;br /&gt;
=== Pointers ===&lt;br /&gt;
&amp;lt;code&amp;gt;constexpr&amp;lt;/code&amp;gt; Pointers are implicitly const, i.e you cannot change where the pointer points to but you can change the data at the memory address. &lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
static constexpr int x = 5&lt;br /&gt;
static constexpr int y = 10;&lt;br /&gt;
constexpr int* integer = &amp;amp;x; // Equivalent to 'int* const integer = &amp;amp;x' but evaluated at compile time&lt;br /&gt;
&lt;br /&gt;
integer = &amp;amp;y // Error, cannot retarget the pointer&lt;br /&gt;
*integer = 15 // Valid, value of x is changed to 15 &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To ensure the pointer is evaluated at compile time, cannot be retargeted and is not able to change its target a &amp;lt;code&amp;gt;const&amp;lt;/code&amp;gt; keyword can be added after &amp;lt;code&amp;gt;constexpr&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
static constexpr int x = 5;&lt;br /&gt;
static constexpr int y = 10;&lt;br /&gt;
constexpr const int* integer = &amp;amp;x; // Equivalent to 'const int* const integer = &amp;amp;x' but guaranteed to be evaluated at compile time.&lt;br /&gt;
&lt;br /&gt;
integer = &amp;amp;y;  // Error, Cannot Retarget the pointer&lt;br /&gt;
*integer = 15; // Error, the value at the pointed address cannot be modified.  &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Functions === &lt;br /&gt;
Functions can also be evaluated at compile time by using the keyword &amp;lt;code&amp;gt;constexpr&amp;lt;/code&amp;gt; which means &amp;quot;should be usable in a constant expression when given constant expressions as arguments.&amp;quot; &lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
constexpr double square(double x) {return x * x;}&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
If the arguments to a function is a constexpr the function returns a constexpr.&lt;br /&gt;
&lt;br /&gt;
To declare a function as a constexpr, the function cannot contain: &lt;br /&gt;
&lt;br /&gt;
# ASM definition {&amp;lt;code&amp;gt;movl $7, %eax&amp;lt;/code&amp;gt;}&lt;br /&gt;
# A &amp;lt;code&amp;gt;goto&amp;lt;/code&amp;gt; statement &lt;br /&gt;
# A statement with a label other than case and default {&amp;lt;code&amp;gt;label: take that compiler&amp;lt;/code&amp;gt;}&lt;br /&gt;
# A try-block {&amp;lt;code&amp;gt;try {std::cout &amp;lt;&amp;lt; &amp;quot;My dick stinks&amp;quot; &amp;lt;&amp;lt; std:endl; }&amp;lt;/code&amp;gt;}&lt;br /&gt;
# Variable definition of non-literal type {&amp;lt;code&amp;gt;MyCustomClass anObject&amp;lt;/code&amp;gt;}&lt;br /&gt;
# Static variable &lt;br /&gt;
# Uninitialized variable &lt;br /&gt;
&lt;br /&gt;
Why do you care? Constexpr function are a good way to write cleaner code as compared to using macros everywhere, improve performance (but rarely used for this purpose)&lt;br /&gt;
&lt;br /&gt;
=== Constexpr Classes === &lt;br /&gt;
&lt;br /&gt;
Simple user-defined classes can also be used as constant expressions. &lt;br /&gt;
&lt;br /&gt;
To make a class a &amp;lt;code&amp;gt;constexpr&amp;lt;/code&amp;gt; class it needs to have a &amp;lt;code&amp;gt;constexpr&amp;lt;/code&amp;gt; constructor with an empty body and all member functions should be initialized by constant expressions. &lt;br /&gt;
&lt;br /&gt;
Declaring a constructor as &amp;lt;code&amp;gt;constexpr&amp;lt;/code&amp;gt; turns your class into &amp;quot;User Defined Literals&amp;quot; i.e. you class can now be used as a literal&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Planet Chili Tutorial Video == &lt;br /&gt;
* [[Beginner C++ Game Programming Tutorial 9]]&lt;br /&gt;
&lt;br /&gt;
== Other Tutorials == &lt;br /&gt;
&lt;br /&gt;
* https://hackernoon.com/a-tour-of-c-17-if-constexpr-3ea62f62ff65&lt;br /&gt;
&lt;br /&gt;
* https://www.geeksforgeeks.org/understanding-constexper-specifier-in-c/&lt;br /&gt;
&lt;br /&gt;
* https://en.cppreference.com/w/cpp/language/constexpr&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
* [[Beginner_C++_Game_Programming_Series#Topics_Covered|List of Beginner C++ Topics]]&lt;/div&gt;</summary>
		<author><name>Rudra</name></author>	</entry>

	<entry>
		<id>https://wiki.planetchili.net/index.php?title=Constexpr&amp;diff=1488</id>
		<title>Constexpr</title>
		<link rel="alternate" type="text/html" href="https://wiki.planetchili.net/index.php?title=Constexpr&amp;diff=1488"/>
				<updated>2018-09-02T04:03:27Z</updated>
		
		<summary type="html">&lt;p&gt;Rudra: /* Basics */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;code&amp;gt;constexpr&amp;lt;/code&amp;gt; is a keyword applied to variables and functions. It's basically the same as the &amp;lt;code&amp;gt;[[http://wiki.planetchili.net/index.php?title=Const const]]&amp;lt;/code&amp;gt; keyword but enforces an additional rule that &amp;quot;The value of this const will be available at compile time&amp;quot; &lt;br /&gt;
&lt;br /&gt;
== Difference between const &amp;amp; constexpr ==&lt;br /&gt;
=== Basics ===&lt;br /&gt;
In C++ there can be 2 types of constants: &lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Whose value is known at compile time.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
const int x = 50;&lt;br /&gt;
const int z = x + 1; &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
During compile time, the compiler knows the value of x and z would be 50 and 51 respectively. And the values won’t change throughout the lifetime of the program. So it goes “I’ll just substitute all the references to x and z with 50 and 51, instead of looking up what the values of x and z every time during runtime”.&lt;br /&gt;
&lt;br /&gt;
This allows 50 and 51 to be used as literals (hardcoded values) with all their advantages and at the same time not clutter our code with random numbers that are hard to interpret the meaning of.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol start=&amp;quot;2&amp;quot; style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Whose value is not known at compile time.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;source&amp;gt;const int y = GenRandomNumber();&amp;lt;/source&amp;gt;&lt;br /&gt;
In this case the value of y would be impossible to determine at compile time as a we don’t know what random number would be generated at runtime.&lt;br /&gt;
&lt;br /&gt;
NOTE: the variable is still a constant, once a random number is assigned to it the value cannot change.&lt;br /&gt;
&lt;br /&gt;
When the compiler comes across scenario #1 it marks x an z as constant expressions i.e. their value can be evaluated at compile time and in scenario #2 marks y as being a constant but not a constant expression as it can only be evaluated during runtime.&lt;br /&gt;
&lt;br /&gt;
This can be a bit confusing in certain contexts e.g.&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
int anArray[x]; // Compiles successfully &lt;br /&gt;
int anotherArray[y]; // Fails compilation &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Certain operations require compile-time knowledge of a variable, in this case, anotherArray declaration would throw an error even though y is a const just like x. This is because the value of y cannot be computed until the function GenRandomNum() is run.&lt;br /&gt;
&lt;br /&gt;
Due to this confusion, it is hard to evaluate what constants will be available during compile time, and which won’t like in our example above. As your code base gets bigger this can spiral out of control, as multiple people are working on the same code base.&lt;br /&gt;
&lt;br /&gt;
This is where the keyword &amp;lt;code&amp;gt;constexpr&amp;lt;/code&amp;gt; comes in as it tells the compiler that the value of this variable should be deduced at compile time to allow for scenarios such as the one above. If y was declared as &amp;lt;code&amp;gt; constexpr int y = GetRandomNumber()&amp;lt;/code&amp;gt; the compiler would throw an error that the value cannot be evaluated at compile time. It clarifies the intended use of the variable.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
constexpr int y = GetRandomNumber(); // error&lt;br /&gt;
constexpr int y = 69; // Compiles fine&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Planet Chili Tutorial Video == &lt;br /&gt;
* [[Beginner C++ Game Programming Tutorial 9]]&lt;br /&gt;
&lt;br /&gt;
== Other Tutorials == &lt;br /&gt;
&lt;br /&gt;
* https://hackernoon.com/a-tour-of-c-17-if-constexpr-3ea62f62ff65&lt;br /&gt;
&lt;br /&gt;
* https://www.geeksforgeeks.org/understanding-constexper-specifier-in-c/&lt;br /&gt;
&lt;br /&gt;
* https://en.cppreference.com/w/cpp/language/constexpr&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
* [[Beginner_C++_Game_Programming_Series#Topics_Covered|List of Beginner C++ Topics]]&lt;/div&gt;</summary>
		<author><name>Rudra</name></author>	</entry>

	<entry>
		<id>https://wiki.planetchili.net/index.php?title=Constexpr&amp;diff=1487</id>
		<title>Constexpr</title>
		<link rel="alternate" type="text/html" href="https://wiki.planetchili.net/index.php?title=Constexpr&amp;diff=1487"/>
				<updated>2018-09-02T04:01:22Z</updated>
		
		<summary type="html">&lt;p&gt;Rudra: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;code&amp;gt;constexpr&amp;lt;/code&amp;gt; is a keyword applied to variables and functions. It's basically the same as the &amp;lt;code&amp;gt;[[http://wiki.planetchili.net/index.php?title=Const const]]&amp;lt;/code&amp;gt; keyword but enforces an additional rule that &amp;quot;The value of this const will be available at compile time&amp;quot; &lt;br /&gt;
&lt;br /&gt;
== Difference between const &amp;amp; constexpr ==&lt;br /&gt;
=== Basics ===&lt;br /&gt;
In C++ there can be 2 types of constants: &lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Whose value is known at compile time.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
const int x = 50;&lt;br /&gt;
const int z = x + 1; &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
During compile time, the compiler knows the value of x and z would be 50 and 51 respectively. And the values won’t change throughout the lifetime of the program. So it goes “I’ll just substitute all the references to x and z with 50 and 51, instead of looking up what the values of x and z every time during runtime”.&lt;br /&gt;
&lt;br /&gt;
This allows 50 and 51 to be used as literals (hardcoded values) with all their advantages and at the same time not clutter our code with random numbers that are hard to interpret the meaning of.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol start=&amp;quot;2&amp;quot; style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Whose value is not known at compile time.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;source&amp;gt;const int y = GenRandomNumber();&amp;lt;/source&amp;gt;&lt;br /&gt;
In this case the value of y would be impossible to determine at compile time as a we don’t know what random number would be generated at runtime.&lt;br /&gt;
&lt;br /&gt;
NOTE: the variable is still a constant, once a random number is assigned to it the value cannot change.&lt;br /&gt;
&lt;br /&gt;
When the compiler comes across scenario #1 it marks x an z as constant expressions i.e. their value can be evaluated at compile time and in scenario #2 marks y as being a constant but not a constant expression as it can only be evaluated during runtime.&lt;br /&gt;
&lt;br /&gt;
This can be a bit confusing in certain contexts e.g.&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
int anArray[x]; // Compiles successfully &lt;br /&gt;
int anotherArray[y]; // Fails compilation &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Certain operations require compile-time knowledge of a variable, in this case, anotherArray declaration would throw an error even though y is a const just like x. This is because the value of y cannot be computed until the function GenRandomNum() is run.&lt;br /&gt;
&lt;br /&gt;
Due to this confusion, it is hard to evaluate what constants will be available during compile time, and which won’t like in our example above. As your code base gets bigger this can spiral out of control, as multiple people are working on the same code base.&lt;br /&gt;
&lt;br /&gt;
This is where the keyword &amp;lt;code&amp;gt;constexpr&amp;lt;/code&amp;gt; comes in as it tells the compiler that the value of this variable should be deduced at compile time to allow for scenarios such as the one above. If y was declared as &amp;lt;code&amp;gt; constexpr int y = GetRandomNumber()&amp;lt;/code&amp;gt; the compiler would throw an error that the value cannot be evaluated at compile time. It clarifies the intended use of the variable.&lt;br /&gt;
&lt;br /&gt;
== Planet Chili Tutorial Video == &lt;br /&gt;
* [[Beginner C++ Game Programming Tutorial 9]]&lt;br /&gt;
&lt;br /&gt;
== Other Tutorials == &lt;br /&gt;
&lt;br /&gt;
* https://hackernoon.com/a-tour-of-c-17-if-constexpr-3ea62f62ff65&lt;br /&gt;
&lt;br /&gt;
* https://www.geeksforgeeks.org/understanding-constexper-specifier-in-c/&lt;br /&gt;
&lt;br /&gt;
* https://en.cppreference.com/w/cpp/language/constexpr&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
* [[Beginner_C++_Game_Programming_Series#Topics_Covered|List of Beginner C++ Topics]]&lt;/div&gt;</summary>
		<author><name>Rudra</name></author>	</entry>

	<entry>
		<id>https://wiki.planetchili.net/index.php?title=Constexpr&amp;diff=1486</id>
		<title>Constexpr</title>
		<link rel="alternate" type="text/html" href="https://wiki.planetchili.net/index.php?title=Constexpr&amp;diff=1486"/>
				<updated>2018-09-02T03:40:39Z</updated>
		
		<summary type="html">&lt;p&gt;Rudra: Created page with &amp;quot;&amp;lt;code&amp;gt;constexpr&amp;lt;/code&amp;gt; is a keyword applied to variables and functions. It's basically the same as the &amp;lt;code&amp;gt;http://wiki.planetchili.net/index.php?title=Const const&amp;lt;/code&amp;gt;...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;code&amp;gt;constexpr&amp;lt;/code&amp;gt; is a keyword applied to variables and functions. It's basically the same as the &amp;lt;code&amp;gt;[[http://wiki.planetchili.net/index.php?title=Const const]]&amp;lt;/code&amp;gt; keyword but enforces an additional rule that &amp;quot;The value of this const will be available at compile time&amp;quot; &lt;br /&gt;
&lt;br /&gt;
== Difference between const &amp;amp; constexpr ==&lt;br /&gt;
=== Basics ===&lt;br /&gt;
In C++ there can be 2 types of constants: &lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Whose value is known at compile time.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
const int x = 50;&lt;br /&gt;
const int z = x + 1; &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
During compile time, the compiler knows the value of x and z would be 50 and 51 respectively. And the values won’t change throughout the lifetime of the program. So it goes “I’ll just substitute all the references to x and z with 50 and 51, instead of looking up what the values of x and z every time during runtime”.&lt;br /&gt;
&lt;br /&gt;
This allows 50 and 51 to be used as literals (hardcoded values) with all their advantages and at the same time not clutter our code with random numbers that are hard to interpret the meaning of.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol start=&amp;quot;2&amp;quot; style=&amp;quot;list-style-type: decimal;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Whose value is not known at compile time.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;source&amp;gt;const int y = GenRandomNumber();&amp;lt;/source&amp;gt;&lt;br /&gt;
In this case the value of y would be impossible to determine at compile time as a we don’t know what random number would be generated during runtime.&lt;br /&gt;
&lt;br /&gt;
NOTE: the variable is still a constant, once a random number is assigned to it the value cannot change.&lt;br /&gt;
&lt;br /&gt;
When the compiler comes across scenario #1 it marks x an z as constant expressions i.e. their value can be evaluated at compile time and in scenario #2 marks y as being a constant but not a constant expression as it can only be evaluated during runtime.&lt;br /&gt;
&lt;br /&gt;
This can be a bit confusing in certain contexts e.g.&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
int anArray[x]; // Compiles successfully &lt;br /&gt;
int anotherArray[y]; // Fails compilation &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Certain operations require compile-time knowledge of a variable, in this case, anotherArray declaration would throw an error even though y is a const just like x. This is because the value of y cannot be computed until the function GenRandomNum() is run.&lt;br /&gt;
&lt;br /&gt;
Due to this confusion, it is hard to evaluate what constants will be available during compile time, and which won’t like in our example above. As your code base gets bigger this can spiral out of control, as multiple people are working on the same code base.&lt;br /&gt;
&lt;br /&gt;
This is where the keyword &amp;lt;code&amp;gt;constexpr&amp;lt;/code&amp;gt; comes in as it tells the compiler that the value of this variable should be deduced at compile time to allow for scenarios such as the one above. If y was declared as &amp;lt;code&amp;gt; constexpr int y = GetRandomNumber()&amp;lt;/code&amp;gt; the compiler would throw an error that the value cannot be evaluated at compile time. It clarifies the intended use of the variable.&lt;br /&gt;
&lt;br /&gt;
== Planet Chili Tutorial Video == &lt;br /&gt;
* [[Beginner C++ Game Programming Tutorial 9]]&lt;br /&gt;
&lt;br /&gt;
== Other Tutorials == &lt;br /&gt;
&lt;br /&gt;
* https://hackernoon.com/a-tour-of-c-17-if-constexpr-3ea62f62ff65&lt;br /&gt;
&lt;br /&gt;
* https://www.geeksforgeeks.org/understanding-constexper-specifier-in-c/&lt;br /&gt;
&lt;br /&gt;
* https://en.cppreference.com/w/cpp/language/constexpr&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
* [[Beginner_C++_Game_Programming_Series#Topics_Covered|List of Beginner C++ Topics]]&lt;/div&gt;</summary>
		<author><name>Rudra</name></author>	</entry>

	<entry>
		<id>https://wiki.planetchili.net/index.php?title=Arrays&amp;diff=1481</id>
		<title>Arrays</title>
		<link rel="alternate" type="text/html" href="https://wiki.planetchili.net/index.php?title=Arrays&amp;diff=1481"/>
				<updated>2018-09-01T09:55:07Z</updated>
		
		<summary type="html">&lt;p&gt;Rudra: Created page with &amp;quot;Arrays are a collection of elements usually of the same type grouped together and referenced using an index to a unique identifier.   If you think of variables as boxes in whi...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Arrays are a collection of elements usually of the same type grouped together and referenced using an index to a unique identifier. &lt;br /&gt;
&lt;br /&gt;
If you think of variables as boxes in which you can keep stuff and label them &amp;lt;code&amp;gt;box0&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;box1&amp;lt;/code&amp;gt; ... arrays can be thought of as a large box with compartments in it, where the box can be called &amp;lt;code&amp;gt;box&amp;lt;/code&amp;gt; and each compartment is labeled &amp;lt;code&amp;gt;box[0]&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;box[1]&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;box[2]&amp;lt;/code&amp;gt; and so on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Using Arrays ==&lt;br /&gt;
=== Syntax ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
// create a big box that stores integers with 10 compartments&lt;br /&gt;
int box[10];&lt;br /&gt;
&lt;br /&gt;
// Now to put values in these compartments all we have to do is&lt;br /&gt;
box[0] = 50;&lt;br /&gt;
box[1] = 89;&lt;br /&gt;
box[2] = 69;&lt;br /&gt;
box[3] = 50;&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
box[9] = 30;&lt;br /&gt;
&lt;br /&gt;
// NOTE - There are 10 comparments in the box, so we start with compartment 0 &lt;br /&gt;
//        and go all the way to compartment 9.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice how the array declaration follows the format: &lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
// TypeOfBox NameOfBox[CompartmentsInBox]&lt;br /&gt;
	int       box         [10]&lt;br /&gt;
&lt;br /&gt;
// To get access to a compartment use use the syntax  &lt;br /&gt;
// NameOfBox[CompartmentNumber]&lt;br /&gt;
	box[0] // Gives you access to the first compartment in the box. &lt;br /&gt;
	box[1] // Gives access to the second compartment&lt;br /&gt;
   box[9] // Gives access to the last compartment&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Other ways to declare an array: &lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
// An array of 20 ints&lt;br /&gt;
int box[20];&lt;br /&gt;
&lt;br /&gt;
// An array of 5 ints where the first three values are initialised, the other two have default values&lt;br /&gt;
int box[5] = {50, -35, 69};&lt;br /&gt;
&lt;br /&gt;
// Create an array of ints and initialize all elements to zero&lt;br /&gt;
int box[10] = {}&lt;br /&gt;
&lt;br /&gt;
// Both of these statements define an array of 3 ints initializes them with the values provided. &lt;br /&gt;
int box[] = {50, 23, 40};&lt;br /&gt;
int box[]{50, 23, 40};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The size of the array should be known at compile time and the size cannot be changed throughout the lifetime of the program. This is because the space for your container needs to be known at compile time&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
// FAIL &lt;br /&gt;
int size = 10;&lt;br /&gt;
int box[size]; // Error: Here the variable value can be changed during the life of the program because it is not a constant&lt;br /&gt;
&lt;br /&gt;
// PASS&lt;br /&gt;
constexp int size = 10; //  When using constexr it is guaranteed that size won't be changed and it will be known at complie time.&lt;br /&gt;
int box[size];&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Accessing compartments that don't exist is a common mistake, in debug mode you'll get an error but bad things will happen in release mode. Especially be careful while accessing the last compartment of the array. &lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
box[20] = 69 // Gives an error as our box only has 10 compartments and we're trying to access the 21st compartment. &lt;br /&gt;
box[10] = 69 // Again gives an error as our box has 10 compartments starting at 0, and going upto 9&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== But why arrays ?  ===&lt;br /&gt;
Imagine you wanted to store the health of 10 enemies you could store them as enemyHealth0, enemyHealth1 and so on&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
// Store the health of 10 enemies &lt;br /&gt;
int enemyHealth0 = 44&lt;br /&gt;
int enemyHealth1 = 35&lt;br /&gt;
int enemyHealth2 = 45&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
int enemyHealth9 = 84&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
So far so good, now lets say you wanted to display the health of all 10 of your enemies&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
DisplayHealth(enemyHealth0);&lt;br /&gt;
DisplayHealth(enemyHealth1);&lt;br /&gt;
DisplayHealth(enemyHealth2);&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
DisplayHealth(enemyHealth9);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
As you can probably see that you need to type DisplayHealth() repeatedly , what if we could do the same thing but with a lot less code ? That's where arrays come in: &lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
// Declare an array of size 10 and set health variables to&lt;br /&gt;
int enemyHealth[10] = {44, 35, 45 ... 84};&lt;br /&gt;
&lt;br /&gt;
// use a for loop to diplay enemy health&lt;br /&gt;
for(int i = 0; i &amp;lt; 10; i++)&lt;br /&gt;
{&lt;br /&gt;
	DisplayHealth(enemyHealth[i]);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
We could do the same if we wanted to kill off all enemies, just go through an array of all the enemies and kill them. &lt;br /&gt;
Arrays work really well with loops, in the above example we only had 10 values, but imagine if we had 100 values we could just loop over all of them with the same code by just changing the condition to &amp;lt;code&amp;gt;i &amp;lt; 100 &amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== What's really going on here tho == &lt;br /&gt;
When you create an array e.g. &amp;lt;code&amp;gt;int box[10]&amp;lt;/code&amp;gt; your computer takes a portion of your memory and gives a name to that block i.e. &amp;lt;code&amp;gt;box&amp;lt;/code&amp;gt;  in our case. The size of the block is decided by the type of the array. In our case int, a single int is &amp;lt;code&amp;gt;4 bytes&amp;lt;/code&amp;gt;  in size [https://msdn.microsoft.com/en-us/library/s3f49ktz.aspx MSDN Reference] and we need space to store 10 ints so your computer allocates &amp;lt;code&amp;gt;10 x 4 bytes&amp;lt;/code&amp;gt; of memory i.e. &amp;lt;code&amp;gt;40 bytes&amp;lt;/code&amp;gt; of memory where each int occupies 4 bytes one after the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now when you access the third compartment in your array &amp;lt;code&amp;gt;box&amp;lt;/code&amp;gt; and use the syntax &amp;lt;code&amp;gt;box[3]&amp;lt;/code&amp;gt;. Your CPU says I am going to go to the starting point of box , you want the 3rd compartment? Ok, so each compartment is &amp;lt;code&amp;gt;4bytes&amp;lt;/code&amp;gt; long (int) so to get to the third compartment I can take the starting point of block and move 3 times the size of each compartment, which in our case would be &amp;lt;code&amp;gt;3 * 4 = 12 bytes&amp;lt;/code&amp;gt; . Now we are at the starting point of the third block. And because the type of the array is an &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt; (size 4 bytes), your CPU knows that the next 4 bytes in the memory block are the contents of compartment 3. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you're starting out with arrays, you don't need to know how arrays work under the hood; more gems will be revealed as you move on to the intermediate series. What's important is that you get a solid understanding of the concept of arrays as being big compartmentalized containers to store stuff that work really well with loops. &lt;br /&gt;
&lt;br /&gt;
== Planet Chili Tutorial Video == &lt;br /&gt;
* [[Beginner C++ Game Programming Tutorial 13]]&lt;br /&gt;
&lt;br /&gt;
== Other Tutorials == &lt;br /&gt;
* http://www.cplusplus.com/reference/array/array/&lt;br /&gt;
&lt;br /&gt;
* https://www.tutorialspoint.com/cplusplus/cpp_arrays.htm&lt;br /&gt;
&lt;br /&gt;
* https://www.programiz.com/cpp-programming/arrays&lt;br /&gt;
&lt;br /&gt;
* https://www.geeksforgeeks.org/arrays-in-c-language-set-1-introduction/&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
* [[Beginner_C++_Game_Programming_Series#Topics_Covered|List of Beginner C++ Topics]]&lt;/div&gt;</summary>
		<author><name>Rudra</name></author>	</entry>

	<entry>
		<id>https://wiki.planetchili.net/index.php?title=References&amp;diff=1456</id>
		<title>References</title>
		<link rel="alternate" type="text/html" href="https://wiki.planetchili.net/index.php?title=References&amp;diff=1456"/>
				<updated>2018-07-06T11:04:49Z</updated>
		
		<summary type="html">&lt;p&gt;Rudra: Created page with &amp;quot;References are a way to access one variable with two names. References are useful when we want to pass a variable to a function and make changes to it inside that function.  =...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;References are a way to access one variable with two names. References are useful when we want to pass a variable to a function and make changes to it inside that function.&lt;br /&gt;
&lt;br /&gt;
== Using References ==&lt;br /&gt;
To understand why we need references let's look at an example: &lt;br /&gt;
&lt;br /&gt;
If we wanted to move our player to the right, one of the ways we could do it is: &lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
// We have x position for our player on screen;&lt;br /&gt;
int posX = 50;&lt;br /&gt;
MoveRight(posX); // Should set posX to 51&lt;br /&gt;
DisplayValue(posX); // Should display 51 on Screen&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// We create a function to move our player 1 unit in x direction&lt;br /&gt;
void MoveRight(int x)&lt;br /&gt;
{&lt;br /&gt;
// Add 1 to the value &lt;br /&gt;
    x = x + 1;&lt;br /&gt;
}&lt;br /&gt;
// Takes in a variable and Displays its value on the screen&lt;br /&gt;
DisplayValue(int x)&lt;br /&gt;
{&lt;br /&gt;
    // Do some stuff to display the variable on screen&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
After running this code you would expect 51 to be displayed on screen.&lt;br /&gt;
But when you run this code what would actually be displayed is: &lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
//output&lt;br /&gt;
50&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This happens because when you pass posX to the MoveRight function, it creates a copy of posX  and does all the operations on that copy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
// x position of player on screen&lt;br /&gt;
int posX = 50;&lt;br /&gt;
MoveRight(posX);  // Here a copy of posX is created and passed into the MoveRight function&lt;br /&gt;
DispayValue(posX); // Since a copy of posX was incremented and the actual variable is untouched we get an output of 50; &lt;br /&gt;
&lt;br /&gt;
void MoveRight(int x)&lt;br /&gt;
{&lt;br /&gt;
     // Add 1 to the value&lt;br /&gt;
    x = x + 1;    // The copy of posX is incremented by 1&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Passing by Reference ===&lt;br /&gt;
Now, to move our player we want actual value of posX to change and not of a copy, so we need to grab c++ by the collar and tell it &amp;quot;listen to me, I do NOT want you to create a copy of my variable but change the original variable instead&amp;quot;. If we change our MoveRight function to:&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
// Add an &amp;amp; after int - This tells c++ not to copy the value of whatever variable is passed in but to use 'x' as an alias for that variable&lt;br /&gt;
void MoveRight(int&amp;amp; x)&lt;br /&gt;
{&lt;br /&gt;
    // x is an alias for posX&lt;br /&gt;
    x = x + 1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Now if we were to run the same code: &lt;br /&gt;
&amp;lt;source&amp;gt; &lt;br /&gt;
int posX = 50;&lt;br /&gt;
MoveRight(posX);  // Now the address of posX is passed onto x and it becomes an alias for posX &lt;br /&gt;
DispayValue(posX); // Here we get an output of 51&lt;br /&gt;
&lt;br /&gt;
// Add an &amp;amp; after int - This tells c++ not to copy the value of whatever variable is passed in but to use 'x' as an alias for that variable&lt;br /&gt;
void MoveRight(int&amp;amp; x)&lt;br /&gt;
{&lt;br /&gt;
    // x is an alias for posX&lt;br /&gt;
    x = x + 1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Here by using the &amp;lt;code&amp;gt;&amp;amp;&amp;lt;/code&amp;gt; sign when declaring the function, we instruct c++ not to copy the variable passed but use x as another name for posX. So whatever changes you make to x will be reflected on posX. This is also called passing by reference.&lt;br /&gt;
&lt;br /&gt;
==  What's really going on here tho == &lt;br /&gt;
We know that we can create multiple variables, you can also think of variables as boxes where you can store data. But where are those boxes actually stored? In your computers memory. And how does your computer find that box when it needs to access the value ? It does it just like a postman finds your house when you get a letter i.e. by looking up your address. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Similarly, each of these boxes (variables) have addresses just like houses on a street would. So when you add the '&amp;amp;' sign like we did in the example above, you are telling c++ : Every time someone passes a variable into this function, take the address of that variable and refer to data at that address using the newly declared variable (x in our case). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Passing by reference is also faster than passing by value as you are not creating copies of the variable every time you call the function. &lt;br /&gt;
&lt;br /&gt;
== Planet Chili Tutorial Video ==&lt;br /&gt;
* [[Beginner C++ Game Programming Tutorial 10]]&lt;br /&gt;
&lt;br /&gt;
== Other Tutorials == &lt;br /&gt;
* [https://www.tutorialspoint.com/cplusplus/cpp_references.htm Tutorials Point]&lt;br /&gt;
* [https://www.cprogramming.com/tutorial/references.html References and Efficieny]&lt;br /&gt;
* [http://www.cplusplus.com/doc/tutorial/pointers/ References and Pointers]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
* [[Beginner_C++_Game_Programming_Series#Topics_Covered|List of Beginner C++ Topics]]&lt;/div&gt;</summary>
		<author><name>Rudra</name></author>	</entry>

	<entry>
		<id>https://wiki.planetchili.net/index.php?title=If_Statement&amp;diff=1420</id>
		<title>If Statement</title>
		<link rel="alternate" type="text/html" href="https://wiki.planetchili.net/index.php?title=If_Statement&amp;diff=1420"/>
				<updated>2018-06-13T10:36:37Z</updated>
		
		<summary type="html">&lt;p&gt;Rudra: Created page with &amp;quot;If statements are a way to make decisions in your program. e.g., if the player presses Space Bar, make the player jump or IF the health is 0, end the game.   == Using If State...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;If statements are a way to make decisions in your program. e.g., if the player presses Space Bar, make the player jump or IF the health is 0, end the game. &lt;br /&gt;
&lt;br /&gt;
== Using If Statements ==&lt;br /&gt;
When making a decision in your program, two things need to happen &lt;br /&gt;
# You need to evaluate the condition.&lt;br /&gt;
# There should be a set of instructions(code) to execute based on that condition.&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
if(condition == true)&lt;br /&gt;
{&lt;br /&gt;
    // Do something&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We use the &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; keyword followed by opening and closing parentheses &amp;lt;code&amp;gt;()&amp;lt;/code&amp;gt; which contain the condition we want to evaluate followed by the block of code (surrounded by &amp;lt;code&amp;gt;{}&amp;lt;/code&amp;gt;) that needs to be executed if that condition is true. &lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
int PlayerHealth = 50;&lt;br /&gt;
if(PlayerHealth &amp;gt; 0)        // Check the condition, if it is evaluated to be true, the code inside the {} is executed &lt;br /&gt;
{&lt;br /&gt;
    // If true, execute some code &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Here we set PlayerHealth to 50. And somewhere in our game, we want to check if the player is still alive, if so we do some shit. &lt;br /&gt;
&lt;br /&gt;
A boolean can also be used as a condition. The code above can be written as: &lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
int playerHealth = 50;&lt;br /&gt;
bool isAlive = (playerHealth &amp;gt; 0);&lt;br /&gt;
if(isAlive)&lt;br /&gt;
{&lt;br /&gt;
    // Do stuff &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If statement is controlled by the value inside &amp;lt;code&amp;gt;()&amp;lt;/code&amp;gt; - Only when it is true, is your code executed. &lt;br /&gt;
&lt;br /&gt;
But what if you want something to happen if the condition is not true, you stick the else keyword at the end: &lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
int playerHealth = 0; &lt;br /&gt;
bool isAlive = (playerHealth &amp;gt; 0);&lt;br /&gt;
if(isAlive) // Evaluated to false&lt;br /&gt;
{&lt;br /&gt;
    // Will not execute&lt;br /&gt;
}&lt;br /&gt;
else // Will execute&lt;br /&gt;
{&lt;br /&gt;
    // You dead &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can even stick if conditions inside if conditions, this is called 'nesting': &lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
std::string Weapon = &amp;quot;Gun&amp;quot;; &lt;br /&gt;
if(Weapon == &amp;quot;Gun&amp;quot;) &lt;br /&gt;
{&lt;br /&gt;
    // Pew Pew Pew &lt;br /&gt;
}&lt;br /&gt;
else &lt;br /&gt;
{&lt;br /&gt;
    if(condition)&lt;br /&gt;
        {&lt;br /&gt;
            // do some stuff &lt;br /&gt;
        }&lt;br /&gt;
    else&lt;br /&gt;
        {&lt;br /&gt;
            // run this block of code&lt;br /&gt;
        }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The code above can be simplified and written as: &lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
std::string Weapon = &amp;quot;Gun&amp;quot;; &lt;br /&gt;
if(Weapon == &amp;quot;Gun&amp;quot;) // Evaluate Condition &lt;br /&gt;
{&lt;br /&gt;
    // Pew Pew Pew &lt;br /&gt;
}&lt;br /&gt;
else if(condition) // *Only* if the first if condition fails, evaluate this, otherwise skip &lt;br /&gt;
{&lt;br /&gt;
  // do some stuff   &lt;br /&gt;
}&lt;br /&gt;
else &lt;br /&gt;
{&lt;br /&gt;
    // run this block of code if everything else fails &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
C++ gives us the &amp;lt;code&amp;gt;else if&amp;lt;/code&amp;gt; keyword that allows us to keep checking for different conditions. You can use as many &amp;lt;code&amp;gt;else if&amp;lt;/code&amp;gt; as you want, but remember it will only run if the condition before it has failed.&lt;br /&gt;
&lt;br /&gt;
== What's really going on here tho == &lt;br /&gt;
When you run your program all your c++ code is converted to machine code all of which is loaded into memory. When you use an if statement, you're effectively telling your computer - if this condition is true then jump to this part of memory. If you care about performance(you should you are using c++) you should know that this jumping around does carry some overhead, very fast code does try to avoid if statements in clever ways. If you are just starting out, you don't need to worry about all this. &lt;br /&gt;
&lt;br /&gt;
== Tutorial Videos == &lt;br /&gt;
[[Beginner C++ Game Programming Tutorial 3]]&lt;br /&gt;
&lt;br /&gt;
== See Also == &lt;br /&gt;
https://www.youtube.com/watch?v=qEgCT87KOfc&amp;amp;t=904s&lt;br /&gt;
&lt;br /&gt;
http://www.cplusplus.com/doc/tutorial/control/&lt;br /&gt;
&lt;br /&gt;
https://www.tutorialspoint.com/cplusplus/cpp_if_else_statement.htm&lt;br /&gt;
&lt;br /&gt;
https://www.cprogramming.com/tutorial/lesson2.html&lt;/div&gt;</summary>
		<author><name>Rudra</name></author>	</entry>

	</feed>