Thread: data types

  1. #1
    Registered User wazilian's Avatar
    Join Date
    Oct 2001

    Unhappy data types

    a couple of questions here:
    (Just pretend that i am a complete moron, where as i am only half a moron now, thanx in advance)

    -can data types be miss-matched without errors?
    -can data types hold the same kind of data if the values are in the same range?
    -typically, what is the difference between int, short int, and char?

    thanx, thats all for now!!!
    King of Wazil

  2. #2
    Registered User
    Join Date
    Dec 2001
    what do you mean with data-types?
    the variable type? int, char,...?

    if you cast one variable it can become any type you want - so it is not save!

    think about following:
    int num=atoi((char*)5);

    the compiler won't complain about that, but 5 isn't a char* so atoi would fail or retun a wrong value

    I don't understand your second question ;-) sorry

    int, short and char

    sizeof(char) is defined as 1 Byte
    int is defined so:

    short is an integer which can store not so a big range as int can but it needs less bytes...

    char means character and it represents a letter!

    in C you can cast int and char implicit - that means
    char c=65;
    is valid!

    c contains the letter with the ascii code 65 (A)

    normally you should use int rather than short or char because most cpu are optimized for int!
    Hope you don't mind my bad english, I'm Austrian!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extending basic data types.
    By nempo in forum C++ Programming
    Replies: 23
    Last Post: 09-25-2007, 03:28 PM
  2. Replies: 4
    Last Post: 06-14-2005, 05:45 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM
  5. Using enumerated data types
    By SXO in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2001, 06:26 PM