The first review
Home Page Parent Page What in Bill Gate'

 

The first review

 

It is time to review all of the things we have gone over. That means I create a program and explain what it does.

#include <iostream.h>  // there should not be any spaces between the < or > and the class name!!

void main ()

{

      unsigned long int num1;     // creates an unsinged int variable called num1
      float num2, num3;     // creates 2 float variables: num2 and num3
      double num4 = 12;     // creates a double variable called num4 and gives it the value of 12
             
      num1 = 7;     // assigns num1 the value of 7
      cout <<num1<< endl;     // displays the value of num1
      cout <<num4<< endl;     // displays the value of num4
      num2 = num4;     // assigns num2 the value of whatever is in num4, 12
      cout <<num2<< endl;     // displays the value of num2
      num1 = 83.8744;     // gives num1 a floating point value
      cout <<num1<< endl;     // displays the truncated value of num1
      cout <<num3<< endl;     // displays garbage! And creates a compiler warning!! This is because num3 is never initialized!

}

 

See! Using variables is not that hard! And we found out that if you put a floating point number into an integer, the integer truncates everything after the period.

We also found out about what is in a variable before you give it a value, garbage. And if you accidentally use the variable with no value, also known as an un-initialized variable, you get a compiler warning.

Another point that needs to be touched on is the difference between data types. If you put the value of a double or float into an integer, and that double or float has a decimal fraction, the fraction is truncated.

And if you put a double into a float, and that double is larger than 3.4 * 10^381, the value is "wrapped" into a negative number. Why? The reason has to do with the binary number systems computers use and is a little complicated.

Well, the review is over. Unless I get some mail, asking for more explanation....

tutorial3.html

 

 

1