Few more noob questions

This is a discussion on Few more noob questions within the C Programming forums, part of the General Programming Boards category; Alright, I've got a few more noobie questions. What is the difference between the variable types: char int float double ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    12

    Red face Few more noob questions

    Alright, I've got a few more noobie questions. What is the difference between the variable types:

    char
    int
    float
    double

    I kind of understand these, but I don't know what the practical application is of knowing how many bytes of memory each one can take up. Sorry for the newb question but I can't really understand it well with what I've been told .

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    char is a letter
    int is a non-decimal number
    float is a less accurate decimal number
    double is a more accurate decimal number

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    12

    Smile

    Quote Originally Posted by master5001 View Post
    char is a letter
    int is a non-decimal number
    float is a less accurate decimal number
    double is a more accurate decimal number
    Thanks . Now is char only a single letter?

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    One single letter.

  5. #5
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    There are finite value ranges for each of these, and chars, shorts, ints, and longs can be signed or unsigned. There are also types like long long, which can also be signed or unsigned, wchar_t, and long double.

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,549
    The problem is that char can only hold so much data because its small size. Therefore there are other types, which are bigger.
    But the bigger the variable, the more memory they consume, so that's generally why there are different types.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by master5001 View Post
    char is a letter
    Or a digit, punctuation mark, or any other character that can be represented by 1 byte.
    Although, that's just if you print it out; it could be used as a very small integer too.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  8. #8
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Yeah but since the question falls within the realm of "very beginner question" as in the guy does not even know how to fathom what the difference is, there is no need to say it is a single byte integral type which stores digits -128 to 127 when signed or 0 to 255 when unsigned. That answer would serve the OP little use.

  9. #9
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,549
    A 2-byte variable (typically short) may hold numbers up to 0 to 65535 (or about -32767 to 32768 +/- 1).
    4 bytes (typically int, sometimes long) can hold up to 4 294 967 295 (that's 4 milliard for the lazy ones). Or about half of that if it's signed.
    There's also often an 8-byte variable (but it's not standard), which can hold huge numbers (typically __int64, sometimes long, long long int).
    That should give you an idea of how much data different types can store, if it helps any.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I knew if I gave it enough time that either laserlight or Elysia would jump in with the range values. Which almost certainly will lead to either matsp or CornedBee posting a more complete list of ranges. Though I don't want to be too presumptuous. Someone else may jump in with the information before the usual suspects have a chance.

  11. #11
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by master5001 View Post
    I knew if I gave it enough time that either laserlight or Elysia would jump in with the range values. Which almost certainly will lead to either matsp or CornedBee posting a more complete list of ranges. Though I don't want to be too presumptuous. Someone else may jump in with the information before the usual suspects have a chance.
    Then after that someone usually posts a quote from the C standard which sometimes sparks a debate about the meaning of the statement (if it's slightly ambiguous) or a debate about how the standard should have been written...
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  12. #12
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,831
    Then somebody brings up Hitler and his poor programming skillz.

  13. #13
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Hey I paid $30 for that standard, I'm going to get all the use out of it that I can.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A bunch of REALLY uber noob questions
    By mcmasterballer in forum C Programming
    Replies: 1
    Last Post: 05-02-2008, 01:43 PM
  2. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  3. 2 very noob questions
    By chasingxsuns in forum C Programming
    Replies: 20
    Last Post: 05-07-2006, 11:04 PM
  4. Noob Questions...
    By Firemagic in forum C++ Programming
    Replies: 4
    Last Post: 04-19-2006, 03:57 PM
  5. just started using CPP, couple of arb NooB questions
    By sempuritoza in forum C++ Programming
    Replies: 1
    Last Post: 01-25-2005, 04:21 AM

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