1K Blog Marathon: Day 40
When you are a programmer, everything you see is a variable. The email you’ve received is a variable. The amount of cash in your bank account is a variable. The picture you take a year ago, the video of a cat that you’ve watched a while ago, even the decision you made if you want chocolate or vanilla is a variable!
What are Variables?
Technically speaking, variables are names or identifiers that you allocate to store a value. In different programming languages, different variable keywords are used, but they give a hint of their usage. For example, in Java we have int, while in VB we have Integer. Some also are very strict in letter casing.
Variables, when holding data, SHOULD be declared with proper value. This is where Data Types will come.
Data Types
Variables follows strict types. In some programming languages, you cannot pass variable from one type to another without casting it first. Here are the different data types.
Variables for handling letters or words
String – This type can handle letter or letters. It can also hold special characters, symbols and even numbers. Common declaration will include double quotations (“ ”).
Ex.
String name = "Christian"
Character / Char – this is a lesser type than String, because it can only hold one character. Declaration needed to be inside single quotations (‘ ‘).
Ex.
Char MiddleInitial = 'D'
Variables for handling numbers
Integer / Int – This variable type holds numbers, specifically integer. It should be a negative or positive whole number. It does not require any quotations.
Ex.
Int phone = 09123456789
Float – float variables are literally “floating point” numbers – meaning it can handle decimal numbers. Compared to Double, it is a lesser variable. It can handle up to 32-bit data, or 7-digit number, often called single-precision.
Ex.
Float germ = 0.000009
Double – just like float, double is a floating point that can handle decimal points. It has 64-bit range and can handle up to 16 digits. It is called double-precision.
Ex.
Double cash = 1000000.000000009
Other number data types includes Decimal, Single, Short and Long.
Variable for handling decisions
Boolean / Bool – This variable handles either 0 or 1, True or False, Yes or No. It doesn’t need quotation marks.
Ex.
Bool areYouLearning = True
Variable for handling binary objects.
Blob – Short for Binary Large Object. This data type is a complex one because it can handle long text (memo), images (bitmaps), videos and others. It stores the data in binary format.
Multidimensional variable handlers
Arrays – this is not really a variable per se, but a list of variables with the same data type. For example, arrays can be a list of 10 integers from 0 to 100.
Dictionary – unlike arrays, Dictionary is a list of variables with different data types. Example is a dictionary of Array of strings, 2 int variables and a blob.
Default variables
Generic / Variant – These variable types are default because whenever a variable is declared without data type, the program will assume that these variables are generic ones.
So that’s it folks! I hope you learn a thing or two from this blog! Thanks for dropping by!
“And that’s one blog, stay hungry!”