What exactly do variables do? I know there are many kinds of variables, but how many different kinds are there and what do they do? The only kind of variable I know of is the Floating Point variable, and I have no idea what that does.
Floating point is a decimal like 0.05
There are several othersCode:float dec = 0.05;
int = whole number (1)
char = character
string = array of characters (or just a string like "hello world")
double = larger float
Those are all I can think of off the top of my head. Variables store data and make your program work. The easiest example I can think of is a counter:
Code:int counter = 1; if (counter == 1) { ..... code here }
DirkFirst Tutorials | Linux Forum
I see. I can see how there would have to be different variables to represent letters and numbers, but why do they have to make a variable dedicated to decimals?
When you're working with numeric data, there are a few different ways that people want to work with it. If you're dealing with scientific applications, you often will need to deal with very large or small values. As a result, you need to be able to store the basic value, say 1.3572, as well as the exponent on the 10, say -3. Then you have a value: 1.3572E-3 that corresponds to 0.0013572. This requires more information that storing simple integer values. On the other hand, integers have properties that don't make sense for decimal values, like successor and predecessor (++ and --). Integers also usually require less memory to store. As a result, people tend to use whichever type of number best corresponds to what is being done. Money gets stored in floats, while counters get stored in ints, for example.
That explains it. I thought all those different variable types were there for... I don't know what, but I didn't see a point. Now I do.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks