CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Oct 2003
    Posts
    51

    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

  2. #2
    Join Date
    Jun 2003
    Location
    Cochin
    Posts
    364
    This is correct.

    integer pointer takes 2 bytes and
    float pointer takes 4 bytes.

  3. #3
    Join Date
    Oct 2003
    Posts
    51
    THANKS JOSCOLLIN
    PUNJABIAN263

  4. #4
    Join Date
    Jan 2004
    Location
    Earth
    Posts
    567
    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

  5. #5
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    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...

  6. #6
    Join Date
    Jun 2003
    Location
    Cochin
    Posts
    364
    Depends on the h/w and os we use.
    Anyway this is true in ANSI C.

  7. #7
    Join Date
    Dec 2003
    Posts
    99
    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

  8. #8
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    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...

  9. #9
    Join Date
    Aug 2002
    Location
    United States
    Posts
    729
    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
  •  





Click Here to Expand Forum to Full Width

Featured