+ 1

Someone should explain variables to my understanding pls

17th Aug 2017, 10:56 PM
Osman Abdul Basit
Osman Abdul Basit - avatar
4 odpowiedzi
+ 5
a variable is like a vessel which has something in it. the vessel is the variable itself (or the name) the thing with is contained in it is the value which is assigned to it. eg string my_name= "Lollipop"; before you define( when you assign a value to the variable) or declare( you just write the variable down and assign a value later) a variable, you must indicate the type of the variable it is. These are the data types. data types are int (for integral or real numbers) float (decimal numbers) string (group of characters in quotation marks) and so much more....... that is when you say int age;//variable age is declared. the value of age must be an integral or real number. int age= 100;//variable age is defined. 100 is an integer value. which means the value of the variable age is 100. also, string myname="lollipop" a string is a group or number of characters enclosed in quotes. that is the value of myname is lollipop. and so much more.....like bool, double, char, etc. ******naming rules****** to give a variable a name, there are many rules to follow. quickly I'll give you a few. - you don't start a variable with a special character or number eg int 2ages. × int +age × int age √ - you dont space variable names eg int account balance × int accountbalance √ int account_balance √ and many more rules. check them. ****note***** c++ is case sensitive. That is it pays attention to capital letterings and the likes. eg string myname; is different from string myName; they are 2 different variables because of the capital N in the second. also, assigning a wrong data type to a variable results in an error. I hope I was able to help a bit. 👌✌
18th Aug 2017, 2:01 PM
Tayo
Tayo - avatar
+ 3
This explanation makes it easier for you to understand both variables and later pointers. Computer memory is accessed by addresses. Imagine it like: ______ |_____| Address#1 |_____| Address#2 |_____| Address#3 |_____| Address#4 Now, when we want to keep something and store it later, we need a container right? Like what Melih said, like a glass. In computer we assign some memory to store data. Now, when you want to store data, first you should know its type. You can't store sticks in a glass or water in a bag. We have basic data types in c++ which you can see in the toturial here. After choosing the dara type we store data into it, for example if you have a number, we store it as 'int'. Here is something more advanced. When we store data, as I said, it is saved in the memory somewhere. For example when you enter: int x = 3; x is now a name for a range of memory. For example if int needs 2 blocks of memory, it may include the blocks with Address#2 and Address#3 and when you use x, you are actually using the data stored in that area of the memory.
18th Aug 2017, 12:16 AM
Ali Rashidi
Ali Rashidi - avatar
+ 2
imagine that all information user input or data is a liquid what do you need to keep those liquids in your hand??? a container like glass or maybe something else ok variables are containers to keep all flow data for later use; thats alll
17th Aug 2017, 11:10 PM
Melih Melik Sonmez
Melih Melik Sonmez - avatar
0
훃횰ㅊㅇㄸㄴㄴㄴㄴ
19th Aug 2017, 1:50 AM
최창배
최창배 - avatar