SizeOf

This is a discussion on SizeOf within the C++ Programming forums, part of the General Programming Boards category; Whats SizeOf?...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    35

    SizeOf

    Whats SizeOf?

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1
    it gives you the size in memory taken up by what you pass into it.
    Ex:
    Code:
    sizeof( int );  // returns the number of bytes for an integer
    
    int array[size];
    sizeof( array );  // returns the total size of the array in bytes
    
    // can be used in combination to find the size of dynamic memory
    int size = sizeof( pointer_to_array )/sizeof( array_type );

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    35
    What determines their sizes?

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145

    eh

    Originally posted by Drakon
    What determines their sizes?
    A Win32 integer is 4 bytes large. 1 byte consists of 8 bits (8*4=32, that's why its called a 32bits variable).
    1 bit can have 2 values (1/0). This means that the integer can have 2^32 different values (which is 4294967296).
    Either from 0 to 4294967296 (unsigned int) or from -2147483647 to +2147483648 (signed int, or simply int).

    A double integer (double) is a 64bit variable, and has therefore 2^64 different values (which is 18446744073709551616, wheee!!! alot more).

    So, the thing that determines the size of a variable is the amount of bytes that it uses.
    As you can see, if you double the amount of bytes doesn't mean doubling the maximum number you can store in it .
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  5. #5
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    base types [variable declaration keywords and their modifiers] depend on the compiler... conglomerate types [structs/unions/arrays/etc] are constructs of those respective and possibly modified base types... the use of sizeof keyword can help make your program more portable at compile and run time... it can vary in the OS as well...
    hasafraggin shizigishin oppashigger...

  6. #6
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145

    Now I'm curious

    >> hasafraggin shizigishin oppashigger...

    What does this mean???
    I've been wondering this for a looong time...
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  7. #7
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    i made a post about it in the gen disc... [intuitively titled 'hasafraggin shizigishin oppashigger'] a long time ago... search and ye shall find...
    hasafraggin shizigishin oppashigger...

  8. #8
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145

    Ok

    Ok, found it
    http://www.cprogramming.com/cboard/s...in+oppashigger

    Hey, can you say that sentence 10 times in a row?
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Malloc,calloc..Sscanf.
    By ozumsafa in forum C Programming
    Replies: 22
    Last Post: 07-26-2007, 01:09 AM
  2. Replies: 14
    Last Post: 06-28-2006, 01:58 AM
  3. finding size of empty char array
    By darsunt in forum C Programming
    Replies: 12
    Last Post: 05-30-2006, 07:23 PM
  4. Cutting up an std::string
    By Shamino in forum C++ Programming
    Replies: 26
    Last Post: 04-04-2006, 11:02 AM
  5. Model not showing up on screen...
    By Shamino in forum Game Programming
    Replies: 14
    Last Post: 03-09-2006, 07:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21