C++ Variables | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

C++ Variables

Im having a bit of trouble fully understanding the concept of the variable. A lot of random words got tossed out of nowhere and I little clue to what the explanation is actually trying to explain. Can someone dumb down the explanation of variables a bit for me?

9th Mar 2020, 2:48 AM
Meliodas
Meliodas - avatar
2 Answers
+ 1
Variables are like boxes, sort of. You can store letters and numbers in them ( by saying var_name = value) and name them almost anything you want. However, there are a few rules: the name has to only include numbers, letters and _. They also cannot be the name of reserved keywords (See https://en.cppreference.com/w/cpp/keyword). Also, they have to have a type (string, int, double, etc.). You can learn more about variable types and variable in general here: https://beginnersbook.com/2017/08/cpp-variables/#:~:text=Types%20of%20variables&text=int%3A%20These%20type%20of%20of,double-precision%20floating%20point%20value.
9th Mar 2020, 3:01 AM
The Boxed Person
The Boxed Person - avatar
+ 1
Variables are stuff that you set a type and a value. For example it could be a Char with the value 'c'. We will name it "mychar". Assuming that is NOT a constant, you can later change the value of mychar to any other character.
9th Mar 2020, 3:02 AM
Fernando Pozzetti
Fernando Pozzetti - avatar