Introduction to C programming/Variables
This page may qualify for speedy deletion because: Page at "21:53, 6 December 2009" version was a stub page. All useful document from this page has been merged to https://en.wikiversity.org/wiki/C_Programming/Variables. This stub page is needed to be delete to clean up the "C programming" course so that students won't be confused by various stub courses If you disagree or intend to fix it, and you have not contributed to it before, you may remove this notice. If you have contributed before and disagree, please explain why on the discussion page, after adding {{hangon}} to the top of the . This will alert curators and custodians to your intention, and may permit you the time to write your explanation. Before deleting check the discussion page, what links here, history (last edit), the page log, and Wikiversity:Deletions. |
variables are used to store values in a program. Just like in algebra. There are 3 types of variables in C-programming, character, integer, and float. A character is, well simply a character such as 'v' or 'a' or 'h'. An integer is a whole number, such as '5' or '10' or '19086'. A float is a decimal number, such as '4.26' or '3.14' or '5.679'.
Before you can store a value in a variable you have to declare it. By declaring a variable your telling the compiler to "take this variable, and make room for a value in the computers memory". then you can define it.
Lets say I wanted to make variable a to be an integer with a value of five. I would do this:
int a; a = 5;
the first line of code (int a;) declares a as an integer. Then a=5 makes the variable a have a value of 5. As you may have noticed, there is an int before a. This is use to declare an integer. To declare a character, you would use char before a and make sure the variable is being declared as a character. You would use float before a to make it a float.