What is the difference between short integer and integer ?
Printable View
What is the difference between short integer and integer ?
A short int can't hold as much as a normal int.
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 :
I do not see any difference :(Quote:
Short Int : 2 bytes : -32,768 to 32 767
Int (16bit) : 2 bytes : -32,768 to 32,767
I think it depends on the compiler, unlike Java and VB (VB only has one compiler anyway :p).
oh...I see.. so i should use short when the Integer is more small ?
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 ?
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.
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.Quote:
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 ?
These are the same thing basically.Code:unsigned long int a;
unsigned long a;
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.
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.
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
Thank you all for helping me to put that more clear in my mind.
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;
}