data types

This is a discussion on data types within the C Programming forums, part of the General Programming Boards category; a couple of questions here: (Just pretend that i am a complete moron, where as i am only half a ...

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

    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!!!
    wazilian
    King of Wazil

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    88
    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:
    sizeof(short)<=sizeof(int)

    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
    that
    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, 04:28 PM
  2. Replies: 4
    Last Post: 06-14-2005, 06:45 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  4. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 07:51 PM
  5. Using enumerated data types
    By SXO in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2001, 07:26 PM

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