Tuesday, January 26, 2010

Basic data types and switch

First of all, I want to continue the question of last week. A nice friend help me get out of the problem. In his word, there are two distinct families of basic data types: integer and floating point.Char is one of the members of integer types. The difference between the char and int is the size. Usually, each char occupies one byte, while the size of int is system-dependent. For 16-bit CPU,int occupies 2 bytes, while int occupies 4 bytes for a 32-bit CPU. So, if I type the code like

char c;
c=print("ABC");
what is going to c is the same as I use the code

int a;
a=print("ABC");
a number 3 will be stored into the variable. But why the output is just ABC?. I have to correct a mistake in the blog 1 at first. The output for the

int a;
a=print("ABC");
printf("%d",a);
should be the ABC3. So, If I use

printf("%d",c);
,the output should be ABC3 as well. But I used the %c instead of %d, so the results presented differently.
This problem is very simple,but I know the importance of the data types through it.So, I am still working on them until I get familiar with them.If some one is interesting in the data types, you can go to the textbook page 21 to check it out.
Now, I think it is the time to back to now. Actually, I don't have much things to write down,because I had only one class this week. But I still want to talk about the switch.
switch(){
case 1:

break 3;
case 2:

break;
case 3:

break;
default:

}
I think break is very convenient. It can help us end the statment at once and jump to the other case in no time. So, we can use switch in various ways. Actually, I have a stupid question about the break. I wonder if break can do like

case 1:
break 3;
case 2:
break 1;
case 3:
break ;

That means if we can do the reverse break. I think may be I should try.

No comments:

Post a Comment