Bookmark(0)

No account yet? Register

In this post I will introduce you to variables and how do they work. I will also show you how to write them in C++. Let’s go on.

Variables are object, or keywords that carry on information, such as letters, symbols, numbers etc. In C++, we classify those variables into string variables (string), int variables (int), float variables (float), char variables (char) and bool variables (bool).

maxresdefault.jpg

String variables

String variables carry information like sentences (text). They can be defined in code as a string.


Int variables

Int variables contain information about a natural number, but without decimals. For example: 1, 2, 3, 123, -123, etc. Int variables can be defined in code by the name int.


Float variables

Float variables are more likely to store decimal numbers, such as 1.23, 0.123, 12.3, -123.0, etc. You can recognize them by the name float, but sometimes they can be identified by the name double.


Char variables

I would say that char variables are almost identical with the string variables, except for this minor detail. Char variables carry information about a single character, like “a” or “B”. You will find them as char.


Bool variables

Short answer: Just true or false statements. Let me show you some examples:
“- Is Charlie going to the cinema with us?

-Yes, he is.”

Therefore, Charlie is going to the cinema with his friends, so the statement is true.

“-Johnny, did you do your homework today?

-No, I didn’t.”

Therefore, Johnny didn’t do his homework that day, so the statement is false.

More examples:

bool charlie_went_to_the_cinema = true

bool johnny_did_his_homework = false

Rating: 3.67/5. From 3 votes.
Please wait...
Subscribe
Notify of
guest
13 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments