|
-
February 14th, 2004, 12:36 AM
#1
int and float pointer variables
Hello guys, i need some help, how many bytes an int, float pointer variable in ram, a am using win2000,xp on intel machine.
i make program that display
code:
--------------------------------------------------------------------------------
int i=4;
int *p;
p=&i;
clrscr();
cout<<p<<endl; //0x8f1fff4
p++;
cout<<p<<endl; //0x8f1fff6
float p1=1.1;
float *p2;
p2=&p1;
cout<<p2<<endl; //0x8f1fff0
p2++;
cout<<p2; //0x8f1fff4
--------------------------------------------------------------------------------
how many bytes these int and float pointers take in ram, according to this it is showing
int * takes 2 bytes
float * takes 4 bytes.
thanks for clearing my concept.
PUNJABIAN263
-
February 14th, 2004, 12:41 AM
#2
This is correct.
integer pointer takes 2 bytes and
float pointer takes 4 bytes.
-
February 14th, 2004, 12:53 AM
#3
-
February 14th, 2004, 01:02 AM
#4
This is correct.
integer pointer takes 2 bytes and
float pointer takes 4 bytes.
That's weird with the following code
Code:
float *TestFloat;
int *TestInt;
unsigned int SizeFloat=sizeof(TestFloat);
unsigned int SizeInt=sizeof(TestInt);
SizeFloat=4 and SizeInt=4 when checked in the debugger.
TDM
-
February 14th, 2004, 04:02 AM
#5
Originally posted by joscollin
This is correct.
integer pointer takes 2 bytes and
float pointer takes 4 bytes.
This is not correct...the size of a pointer is the same and equals 4 bytes on a 32-bit processor...
-
February 14th, 2004, 02:25 PM
#6
Depends on the h/w and os we use.
Anyway this is true in ANSI C.
-
February 15th, 2004, 02:25 AM
#7
Depends on the h/w and os we use.
Anyway this is true in ANSI C.
Are you saying that by ANSI C it is correct that float * and int * can take different sizes?
IMO then using void pointers will make little sense.
Regards
-
February 15th, 2004, 05:34 AM
#8
Originally posted by nsh123
Are you saying that by ANSI C it is correct that float * and int * can take different sizes?
No...ANSI C does not have to do much with it...the size of variables are based on the architecture in the first place...
-
February 15th, 2004, 05:40 AM
#9
pointers are the same size irregardless of type.
char *a;
int *b;
unsigned long *c;
double *d;
no matter what you put, the size is always going to be 4 on a 32 bit system. remember, your pointer is just something that "points" to a spot in memory. if it was only 2 bytes you could only point to memory in the first 64kb and well that obviously doesn't cut it anymore.
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
|