Variables

Bits, Bytes, and Codes

Bits - A bit is the smallest possible data storage in a computer. A bit is either 0 or 1. It is like a switch, either turned on or turned off.

Bytes - A byte is made up of 8 bits. This combination of bits has meaning, just like in the English language we combine letters to create words. The computer sees combinations of bits as different characters, symbols, or digits.

Ascii Code - This is the term for an 8-bit representation of characters, symbols, and digits. This representation is used by most computers and most programming languages. In this method 256 different characters can be represented.

Unicode - This is the term for a 16-bit representation of characters, symbols, and digits. In this method 65,536 characters can be represented.

Combinations - The range or number of characters that can be represented is calculated by taking 2 to the power of the number of bits. We notice that there are two choices for each bit, it can either be 0 or 1. Since each bit has 2 choices, we take 2 to the power of the number of bits in order to determine the total number of different possible combinations.

28 = 256
216 = 65,536

Variables or Identifiers

These are storage places within your program. Many different types can be stored in these locations. They will be discussed shortly, examples are - integer numbers, decimal numbers, characters, strings, etc. The name of the variable is determined by you, the programmer. Note, that although the you arbitrarily decide what the name of the variable is, you should always make your variable names descriptive so that it is easy to recognize what the variable is being use for. There are certain restrictions upon the naming of variables. Variables can begin with or contain:
Letters - upper or lowercase, note C is case sensitive
Underscore ( _ )
Variables can contain digits (0 - 9), however they can not begin with a digit. Finally, there are certain keywords in C that can not be used as variables. An examples are the words 'main' and 'public'. As we have discussed, these words serve a specific purpose and therefore may not be used as variable names. C's keywords are listed in table 2.1 on page 26 of our textbook.

Example Variables

X, pete, Peter_Dobbins, cop3275, _time, y, North, etc.

Commenting

There are two types of comments in C
  1. //
  2. /* */

The first comments out the remainder of the line, from that point on. It can begin the line or be placed in the middle of the line. The second comments a block of text. You must open the comment block with this '/*' and close the comment block with '*/'. As soon as you open the comment everything will be commented until the comment is closed regardless of the number of lines that are spanned.