-
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!!!
-
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!