Thread: Various Variable Questions.

  1. #1
    #junkie
    Join Date
    Oct 2004
    Posts
    240

    Question Various Variable Questions.

    Ok i have a few questions, im going through an "eBook", and over all it describes thing very will without skipping minor details.

    Well one thing it did seem to skip so far is i assume default variables.

    From my understanding, without enum data types, there is Bool, Char, Int, and Float correct?
    Now my question is reguarding default data types i assume. It showed some examples all of a sudden involving stuff like:
    Code:
    double myVariable = 50
    and
    Code:
    unsigned short myVariable = 100
    long myVariableT = 100
    dont mind the numbers in those, im just wondering if short, long, double, ect.. are data types in themselves? Or if they are defaults for other data types.

    The way i assume it is, is that double has the default data type of float, and plain long and short (signed or unsigned) have the default data type of Int.
    so
    Code:
    long myVariable = 100
    is the same as
    Code:
    signed long int myVariable = 100
    Im just assuming this, and assuming im right i just wanna make sure. I understand signed and unsigned in terms of numbers, long and short in terms of bytes and numbers (and possibly letters lol), im just confused with the default data type of just saying long myVaraible or double myVariable.

    Also, they didnt go over double, can someone give me a minor quick rundown? just as simple as "its a bigger version of float, allowing for more numbers".

    And is..
    Code:
    unsigned long double float = myFloat 5000.5894
    correct format? (assuming double even involves float ofcourse).





    Thanks to any questions you choose to reply to , you guys rock hehe. Im lovin C++ too, and ofcourse i know i only know 1 billionth of its possibilities, but none the less all the simple stuff and its potential vs my old potentialess language lol. Thanks all!
    01110111011000010110110001100100011011110010000001 11000101110101011010010111010000100000011011000110 10010110011001100101001000000111100101101111011101 0100100000011011100111010101100010

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    You seem to have it pretty well in control. I've never seen the syntax of

    double float;

    though

    long int;

    long;

    and

    int;

    are all common place enough. To me double is similar to float, but has potentially bigger range of valid values. In the reference I have, double can range e^+/-308 (8 bytes) vs float at e^+/- 38 (4 bytes), but given the variable size of ints, depending on your compiler and OS, I suspect the distinction between float and double is also blurring now that memory is so cheap.

  3. #3
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,090
    Boolean, Character, Integer, and Floating-point are just categories that cover all of the built-in types. Built-in types include:

    Boolean: bool
    Character: char, wchar_t
    Integer: short int (short), int, long int (long)
    Floating-point: float, double, long double

    The Character and Integer types can be signed, unsigned, or plain (which can be one or the other depending other factors). So those are all completely separate types, and you can see how they are related by the category they are in.

  4. #4
    #junkie
    Join Date
    Oct 2004
    Posts
    240
    Ah thank you very much to both your posts, i tried to quick reply but it got lost in the vastness of the internet aparently lol. The character type explanation explains it pretty well too, thanks
    01110111011000010110110001100100011011110010000001 11000101110101011010010111010000100000011011000110 10010110011001100101001000000111100101101111011101 0100100000011011100111010101100010

  5. #5
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    {edit: remove commented paragraph}
    /*let me add that 'unsigned' may be applied to any of those types (with the exception of maybe bool, i never tried, but it wouldn't make much sense to)(yes, even characters can be unsigned)...as you might have guessed unsigned means that the variable does not store negative numbers....*/

    *know that when you go from unsigned to signed that you have to be careful as the values you can store change...for example, a signed int can store values in the range of -32,200 to +32,200 (actually, i'm unsure of EXACT number, but i'm only about 100 or so off)...an unsigned int can store 0 to 64,400 (again, rough estimate)...

    take the following code
    unsigned int a = 60000;
    int b = a;

    the compiler should give you a warning, however if you miss it, you just inadvertantly
    set the value of b to a negative number (in this case)..if a < 32,??? then the conversion to b will be ok, however if it's greater, then the conversion will not work correctly...

    why? to keep it short, both signed and unsigned ints use the same amount of space...signed ints use the high order bit of the variable to signify the sign, while unsigned ints do not which is why you can store up to 64000..


    an int as binary
    <--high order bit | low order bit--> (bit is one 1 or one 0)
    1000 0000 0000 0001 signed = -1;
    1000 0000 0000 0001 unsigned = some really big positive number

    correct me if i'm wrong
    Last edited by misplaced; 10-14-2004 at 04:09 PM. Reason: i'm stupid
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  6. #6
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,090
    Quote Originally Posted by misplaced
    let me add that 'unsigned' may be applied to any of those types (with the exception of maybe bool, i never tried, but it wouldn't make much sense to)(yes, even characters can be unsigned)...as you might have guessed unsigned means that the variable does not store negative numbers....

    <snip>

    correct me if i'm wrong
    As I said above, unsigned and signed can be applied to Character and Integer types. They cannot be applied to Boolean or Floating-point types.

  7. #7
    #junkie
    Join Date
    Oct 2004
    Posts
    240
    ya i understand how signed and unsigned works, like i said i was just wondering what data type double is, and how using long/unsigned without an actual data type (int, float, char) would work.

    Thanks for all your replies
    01110111011000010110110001100100011011110010000001 11000101110101011010010111010000100000011011000110 10010110011001100101001000000111100101101111011101 0100100000011011100111010101100010

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Static Local Variable vs. Global Variable
    By arpsmack in forum C Programming
    Replies: 7
    Last Post: 08-21-2008, 03:35 AM
  2. Need some help...
    By darkconvoy in forum C Programming
    Replies: 32
    Last Post: 04-29-2008, 03:33 PM
  3. which variable can store words?
    By Hunterofman in forum C++ Programming
    Replies: 8
    Last Post: 04-28-2008, 05:59 PM
  4. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  5. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 02:45 PM