Results 1 to 13 of 13

Thread: Variable Types Question

  1. #1
    DaoK
    Guest

    Variable Types Question

    What is the difference between short integer and integer ?

  2. #2
    A short int can't hold as much as a normal int.

  3. #3
    DaoK
    Guest
    Turtle I have re-read the chapter 3 of Sams teach yourself C++ and at the page 43 they show us a graphic who have that :
    Short Int : 2 bytes : -32,768 to 32 767
    Int (16bit) : 2 bytes : -32,768 to 32,767
    I do not see any difference

  4. #4
    I think it depends on the compiler, unlike Java and VB (VB only has one compiler anyway ).

  5. #5
    DaoK
    Guest
    oh...I see.. so i should use short when the Integer is more small ?

  6. #6
    DaoK
    Guest
    I have an other question :

    How is it possible to have something like

    unsigned long int ? I have see that....how can a long can be Integer ?

  7. #7
    jim mcnamara
    Guest
    what a datatype is depends on the machine the compiler works on.

    At work I code on a HPUX 11.0 box and a PC. long on the HP is 32 bits, int is also 32 bits, because it is a 64 bit machine. Short is
    16 bits.

    On the PC short and int are the same in Turbo C, which was supposedly an 'ansi' implementation.

    It is called the implementation, and even though C si supposed 'ansi', just try porting a program written in 'ansi' C from the HP to the PC.

  8. #8
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    Originally posted by DaoK
    I have an other question :

    How is it possible to have something like

    unsigned long int ? I have see that....how can a long can be Integer ?
    A long is basically a bigger integer, and unsigned means it can't hold negative values which makes it able to hold higher positive values. I think in C++ a double is the same as a long in VB, not sure though.
    Code:
    unsigned long int a;
    unsigned long a;
    These are the same thing basically.
    Alcohol & calculus don't mix.
    Never drink & derive.

  9. #9
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    In a 16bit C++ compiler for 16bit CPU(eg. Turbo C++),
    int is 16bit.

    In a 32bit C++ compiler for 32bit CPU(eg VC++),
    int is 32bit.
    I'm a VB6 beginner.

  10. #10
    jim mcnamara
    Guest
    In VB Integer and long are the only whole number datatypes.
    Double, and float in C are like Double and Single in VB

    The number datatypes in ansi C consist of basic types:
    float, double, char, int, long, short

    with modifiers (there are others)
    unsigned, signed, long

    ie., long long (like _int64 in VC++ ), unsigned char, unsigned int

    unsigned means that what is stored in the datatype is interpreted as a postive number or zero. signed means the datatype stores the same bit patterns as before, but they get interpreted differently -ie., negative numbers are stored in integers as one's complement.

    For example unsigned char goes from 0 - 255
    signed char goes from -127 to 127.

  11. #11
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    some more things:

    long int and int and long are the same on 32-bit compilers
    short int and short and int are the same on 16-bit compilers

    long long is supposed to be 64-bit according to ANSI, but VC++ only supports _int64, which is the same, but has another name.

    double and long double are 64-bit, float is 32-bit

    char is 8-bit, short is 16-bit and long is 32-bit

    pointers are either 16, 32 or 64 bit, depending on the machine and compiler
    up to 80286 16-bit
    80386 and pentium 32-bit
    Alpha and IA-64 64-bit
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  12. #12
    DaoK
    Guest
    Thank you all for helping me to put that more clear in my mind.

  13. #13
    Addicted Member
    Join Date
    Jan 2001
    Location
    Little Rock, Ar
    Posts
    151
    You can find out information about your machine by runing code like this


    Code:
    #include <iostream.h>
    #include <limits.h>
    
    
    
    void main()
    {
    	cout << "Bits" << endl;
    	cout << "char = " << (sizeof(char)* 8) << endl;
    	cout << "short = " << (sizeof(short)* 8) << endl;
    	cout << "int = " << (sizeof(int)* 8) << endl;
    	cout << "long = " << (sizeof(long)* 8) << endl;
    	cout << endl;
    
    	cout << "Value Range" << endl;
    	cout << "char = " << CHAR_MIN << ":" << CHAR_MAX << endl;
    	cout << "short = " << SHRT_MIN << ":" << SHRT_MAX << endl;
    	cout << "int = " << INT_MIN << ":" << INT_MAX << endl;
    	cout << "long = " << LONG_MIN << ":" << LONG_MAX << endl;
    	
    }

Posting Permissions

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



Click Here to Expand Forum to Full Width