10 Februari, 2018

C Programming | Know your variables.

Hello, geeks. As I promised in the last post, today I would like to show you stuffs about variables and formatted outputs.

First, variable is some part of memory which is reserved for some value. In other words, variable is a place with an address to assign your value into. Variables always carry something like an identifier, which is known as data type. In C, there are a lot of data types, but for now, I will only present to you guys three common types of data.

1. Integer (int)
Integer can only contain positive and negative numbers. Integer can be represented by doing this.

int number;
int number1 = 1;
int number2 = 2, number3 = 3;
int number4, number5;

number4 = number5 = 0;


You can also assign a character into an integer. Why? Because, character is also a number to begin with, known as ASCII Numbers. For example, A's ASCII is 65, so if you assign A into an integer, int will save the value of its ASCII number, which is 65.

int asci = 'A'; //asci's value will be equal to A's ASCII number.


2. Character (char)
Char can only be assigned by a single character. But, you can also assign them with ASCII Number that represents a character. For example, as I mentioned above, A carries an ASCII number which is 65. So, to assign A into a variable, you can do it by

char mychar = 'A';
char mychar1 = 65; // The value of mychar is equal to value of mychar1.


The difference between integer and char is how computer present them to user. Integer will be presented as numbers, meanwhile char as character itself.


3. Float (float)
Float consists decimal numbers. 0.5, 3.14, 5/2 is float. We can also assign integers into float. So we can assign these values by

float float1 = 0;
float float2 = 0.5;
float float3 = 3.14, float4 = 5/2;


So variables is a place for value to remains. You need three of them to grow, so you better understand them first before you take another step. Int represents only integers, char represents only a single character, and float carries all of numbers and turn them into decimal shape.

Now, we already know our variables. In the next post, I would talk about the formatted outputs. Make sure you keep your head cool, the path isn't gonna be easy, but we can always do it! See ya!

Best regards, Ryu.

If you have some problems about programming, feel free to contact me via e-mail. 
E-mail: ryutaroushirogane@gmail.com
TheCreat0r of Omnipotent.

Tidak ada komentar:

Posting Komentar