Closed Thread
Results 1 to 5 of 5

Thread: Variables

  1. #1
    Sionofdarkness is offline Programming Expert
    Join Date
    Jul 2006
    Posts
    383
    Rep Power
    0

    Variables

    What exactly do variables do? I know there are many kinds of variables, but how many different kinds are there and what do they do? The only kind of variable I know of is the Floating Point variable, and I have no idea what that does.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    dirkfirst is offline Programming Expert
    Join Date
    May 2006
    Posts
    354
    Rep Power
    23
    Floating point is a decimal like 0.05

    Code:
    float dec = 0.05;
    There are several others
    int = whole number (1)
    char = character
    string = array of characters (or just a string like "hello world")
    double = larger float

    Those are all I can think of off the top of my head. Variables store data and make your program work. The easiest example I can think of is a counter:

    Code:
    int counter = 1;
    
    if (counter == 1) { 
      ..... code here
    }

  4. #3
    Sionofdarkness is offline Programming Expert
    Join Date
    Jul 2006
    Posts
    383
    Rep Power
    0
    I see. I can see how there would have to be different variables to represent letters and numbers, but why do they have to make a variable dedicated to decimals?

  5. #4
    Join Date
    Jul 2006
    Posts
    16,486
    Blog Entries
    75
    Rep Power
    143
    When you're working with numeric data, there are a few different ways that people want to work with it. If you're dealing with scientific applications, you often will need to deal with very large or small values. As a result, you need to be able to store the basic value, say 1.3572, as well as the exponent on the 10, say -3. Then you have a value: 1.3572E-3 that corresponds to 0.0013572. This requires more information that storing simple integer values. On the other hand, integers have properties that don't make sense for decimal values, like successor and predecessor (++ and --). Integers also usually require less memory to store. As a result, people tend to use whichever type of number best corresponds to what is being done. Money gets stored in floats, while counters get stored in ints, for example.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  6. #5
    Sionofdarkness is offline Programming Expert
    Join Date
    Jul 2006
    Posts
    383
    Rep Power
    0
    That explains it. I thought all those different variable types were there for... I don't know what, but I didn't see a point. Now I do.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Using Environment Variables
    By AIGuy in forum C and C++
    Replies: 5
    Last Post: 01-23-2011, 02:56 PM
  2. JavaScript Variables
    By Hunter100 in forum JavaScript and CSS
    Replies: 1
    Last Post: 04-02-2010, 05:56 AM
  3. TextOutW and Variables
    By intrinsik4 in forum C and C++
    Replies: 1
    Last Post: 12-16-2009, 06:29 PM
  4. 2 variables and 2 objects
    By Siten0308 in forum C# Programming
    Replies: 3
    Last Post: 10-16-2008, 12:02 PM
  5. Variables
    By clookid in forum PHP Tutorials
    Replies: 1
    Last Post: 01-11-2007, 06:40 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts