|
-
Oct 11th, 2001, 06:14 PM
#1
Variable Types Question
What is the difference between short integer and integer ?
-
Oct 11th, 2001, 06:21 PM
#2
Member
A short int can't hold as much as a normal int.
-
Oct 11th, 2001, 06:44 PM
#3
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
-
Oct 11th, 2001, 06:50 PM
#4
Member
I think it depends on the compiler, unlike Java and VB (VB only has one compiler anyway ).
-
Oct 11th, 2001, 08:28 PM
#5
oh...I see.. so i should use short when the Integer is more small ?
-
Oct 11th, 2001, 08:29 PM
#6
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 ?
-
Oct 11th, 2001, 08:35 PM
#7
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.
-
Oct 11th, 2001, 08:43 PM
#8
Fanatic Member
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.
-
Oct 11th, 2001, 11:06 PM
#9
Hyperactive Member
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.
-
Oct 12th, 2001, 06:09 AM
#10
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.
-
Oct 12th, 2001, 08:51 AM
#11
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.
-
Oct 12th, 2001, 04:25 PM
#12
Thank you all for helping me to put that more clear in my mind.
-
Oct 13th, 2001, 11:47 PM
#13
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|