field length

This is a discussion on field length within the C++ Programming forums, part of the General Programming Boards category; could sombody tell me what the field length of integer and string are please. thanks...

  1. #1
    dac
    dac is offline
    Registered User
    Join Date
    Jan 2006
    Location
    North Yorkshire, England
    Posts
    147

    field length

    could sombody tell me what the field length of integer and string are please.
    thanks

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,668
    What do you mean?

    Without any modifiers, everything prints in exactly the number of required characters.

    If you want to change that, look up the manipulators like setw()
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    dac
    dac is offline
    Registered User
    Join Date
    Jan 2006
    Location
    North Yorkshire, England
    Posts
    147
    sorry if i was a bit vague. what i mean is whats the standard variable lengh of these data types in c++ or are they variable length?
    ps tis for a data dictionary on my coursework btw

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    It's dependant on the compiler (or the OS, or both, I'm not certain, actually), but the only requirement for an int is that it's equal to or greater than a short int and less than or equal to a long int. Generally it's either 4 or 8 bytes.

    A string is of course variable dependant on the length of a string. Assuming by string you mean a constant char*, then the size of the string is equal to the length of the string(plus the null) * the size of a char. A char is 1 byte.
    Sent from my iPadŽ

  5. #5
    dac
    dac is offline
    Registered User
    Join Date
    Jan 2006
    Location
    North Yorkshire, England
    Posts
    147
    hmmm. 8 bytes thats 8 characters???

  6. #6
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    8 characters is 8 bytes.
    Sent from my iPadŽ

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,668
    Ah, OK
    std::string has no length limit (as far as I know), apart from the physical limits of your implementation.

    Numeric types have upper and lower bound limits, see for example
    http://www.unc.edu/depts/case/pgi/pg...r/num_5679.htm
    http://www.opengroup.org/onlinepubs/.../limits.h.html

    The 'C' standard (which C++ adopts) sets down the minimum allowed ranges for things like CHAR and INT, but an implementation is free to choose types which have a larger range.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. Strange string behavior
    By jcafaro10 in forum C Programming
    Replies: 2
    Last Post: 04-07-2009, 07:38 PM
  3. Obtaining source & destination IP,details of ICMP Header & each of field of it ???
    By cromologic in forum Networking/Device Communication
    Replies: 1
    Last Post: 04-29-2006, 02:49 PM
  4. i am not able to figure ot the starting point of this
    By youngashish in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2004, 02:41 AM

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