As I mentioned, I was planning to add to my 'Learn C By Example' page on my website. I wanted to provide a very basic introduction to some of C's basic variable types.
Here is what I had (see example program below)... what distinction would you recommend I make between a float and a double? Would it be safe to say that on most systems a doulbe would be bigger than a float and could therefore provide a higher level of precision. Anyway, tell me what you think... here is the example I put together. I know the program doesn't do anything useful... it is only meant as an introduction to some of C's basic variable types.
Thanks for your input.
/* Variables Program
* Purpose: Demonstrating the creation and assignment of some simple variables.
* Author: Eddie Meyer
* Date: 5 DEC 2005
* Let's create (declare) some variables of different types.
* I've tried to give an indication of what each variable
* will hold by choosing variable names that essentially
* describe what they will be used for. You are always
* recommended to try and do this to help others understand
* your code. Oftentimes, it is you that will need reminding
* of what each variable in your program does. Choosing
* descriptive variable names will prove extremely valuable
* to you when you come to review your code a year or two
* down the line.
/* Create a string (a sequence of characters). Technically,
* there is no such thing as a string variable in C. A string
* is really just a sequence (array) of characters.
* In this program, we will use a string variable to store my
* last name.
/* Create a char (a single character value). For example,
* this could be used to store any single character in the
* In this program, we will use a char variable to store my
* middle initial.
/* Create an integer (a whole number). Example values for
* an integer could be 0, 5, 384, -25 etc. Note, that there
* is no decimal part to an integer.
* In this program, we will use an integer variable to store
* my age.
/* Create a float (a number with a fractional part). Example
* values could be 0.0, -5.6, 312.666 etc.
* In this program, we will use a float variable to store my
* hourly wage (in dollars and cents).
/* Create a double (another number type with a fractional part).
* The difference between a double and a float is that doubles
* are designed to be bigger than floats (basically twice (double)
* as big). Therefore a double is capable of storing a decimal
* value that has a significantly higher level of precision
* than a float.
* In this program, we will use a double variable to provide a
* measure of how much (compared to others) my intelligence
* may be of benefit to humanity. We will want to use a double
* for this, because we know the value will be small.
* Now let's assign some values to the variables that we created
/* Use the 'last_name' variable to store my last name.
* Note the use of double quotes when dealing with strings.
last_name = "Meyer";
/* Use the 'middle_initial' variable to store my middle initial.
* Note the use of single quotes when dealing with chars.
middle_initial = 'J'; /* For Jonathan */
/* Use the 'age' variable to store my age */
age = 30;
/* Use the 'hourly_wage' variable to store my hourly wage
*(in dollars and cents).
hourly_wage = 250.75; /* Yah, I wish it were this much. */
/* Use the 'effect_of_my_intelligence_on_humanity' variable to
* store a measure of how much my intelligence may be of benefit
* to humanity. There is no scientific basis for the value I
* chose to use. I do hope that my impact on humanity will
* indeed be positive however, regardless of how small it may
* turn out to be.
effect_of_my_intelligence_on_humanity = 0.00000000000152;