Thread: data types

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    133

    data types

    Hey guys in c++ there are alot of data types and I was just wondering are items such as long, long double, signed long and unsigned short declared as:

    long double variableName;

    or do they have to be declared like?

    long double int variableName;

    long double char variableName;


    unsigned short int variableName;

    unsigned shot char variableName;
    Last edited by 182; 02-17-2006 at 07:27 PM.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    A double is a different type than an int or a char. You can't declare a variable as a double int or double char.

    The long keyboard can be used to declare a larger integer, or a high precision double:
    long int i;
    long double d;

    Keep in mind that this is implementation defined though. On many systems a long int and a long double are no different than a regular int/double.

    The keywords signed/unsigned can be placed before a type declaration to specify if the variable can hold negative numbers (signed), or positive numbers only (unsigned).

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    133
    Thanks, I also believe there is a signed, unsigned and short are these just for ints or are they for chars as well? Thanks.

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    The only 4 variable types you need to be concerned with are:

    1) int--------whole numbers
    2) double----numbers with decimal points
    3) char------one letter or symbol enclosed in single quotes
    4) string-----one or more letters or symbols enclosed in double quotes
    Last edited by 7stud; 02-17-2006 at 08:47 PM.

  5. #5
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Well, signed and unsigned are for numbers, and short is for a short number. Signed is for negative numbers only and unsigned is for positive numbers only. A regular int has a range of about -2 million to +2 million. Therefore, if you have an unsigned number (positive only) will increase it to about +4 million, since there isn't a need for negative numbers. Same goes for signed. These are strictly for numbers, no characters can be dealt with these data types.

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Quote Originally Posted by 182
    Thanks, I also believe there is a signed, unsigned and short are these just for ints or are they for chars as well? Thanks.
    You can have a signed and unsigned char but not a short char. short is used before int.

  7. #7
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    The only 4 variable types you need to be concerned with are:
    What about bool, wchar_t, and float?

  8. #8
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    5) bool-----has the value true or false

  9. #9
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  10. #10
    Registered User
    Join Date
    Aug 2001
    Location
    Melbourne, Australia
    Posts
    92

    Exclamation

    Quote Originally Posted by Sentral
    Signed is for negative numbers only and unsigned is for positive numbers only. A regular int has a range of about -2 million to +2 million. Therefore, if you have an unsigned number (positive only) will increase it to about +4 million, since there isn't a need for negative numbers. Same goes for signed.
    Just a clarification: signed numbers have a sign associated with them - i.e. an indicator of whether the number is positive or negative - so the equivalent range for the same storage size is halved. So no, signed numbers are not for negative numbers only; they're for both.

    And signed chars are possible... though I'm not sure in what case you'd actually want to use them.

    Cheers,
    Jeff
    psychobrat at gmail

  11. #11
    Registered User
    Join Date
    Feb 2006
    Posts
    65
    range of about -2 million to +2 million
    2 billion, not million... from -2,147,483,648 to 2,147,483,647 exactly but this of course depends on the processor you use.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extending basic data types.
    By nempo in forum C++ Programming
    Replies: 23
    Last Post: 09-25-2007, 03:28 PM
  2. Replies: 4
    Last Post: 06-14-2005, 05:45 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM
  5. Using enumerated data types
    By SXO in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2001, 06:26 PM