We can create variables in C++ using the following syntax:
TYPE varName;
We declare the variable first with the data type, followed by the desired name. For example, if you want to store a person's age, you could do:
int age;
The left-hand side is the data type: an integer. The right-hand side is the variable name.
You can assign a value to a variable like so:
age = 35
Simply add the equal sign for the assignment operation, the value of the variable on the right-hand side. Note this is not a comparison.
You can declare your variable using other types, too. For instance, in the following examples we declare and define the values at the same time:
double circleArea = 3.123;
bool loading = true;
std::string name = "Roger";
A double
is a floating point type that allows for the representation of numbers that have a fractional part.
A bool
is a boolean type that has value that is either true
or false
.
A string
is a sequence of characters. The string
type belongs to the std
namespace.
Here is a program for you to play with
For more lessons on software development, visit NBK Tech World:
https://www.youtube.com/channel/UC3pR7vTMNPNmSk99YIBKUnw
See you there!
Congratulations @nbktechworld! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :
You can view your badges on your Steem Board and compare to others on the Steem Ranking
If you no longer want to receive notifications, reply to this comment with the word
STOP
Do not miss the last post from @steemitboard:
Vote for @Steemitboard as a witness to get one more award and increased upvotes!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Congratulations @nbktechworld! You received a personal award!
You can view your badges on your Steem Board and compare to others on the Steem Ranking
Vote for @Steemitboard as a witness to get one more award and increased upvotes!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit