It really works on VS 2008.I am still searching how to improve the code ,cause I don't think it's professional and I can't explain some of the processes in my own word.
Saturday, January 30, 2010
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.
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.
Monday, January 18, 2010
Question I got
Through the week 1 studying, I learn that
int a;
a=printf("ABC");
will cause a equal 3. Then I am curise that if I use this new thing with char ,what the result will be. So I do a test
char a;
a=printf("ABC");
There is no suprise for the result. It prints ABC. But another question came to my mind. Why it prints ABC instead of just A? I remember that a char can only be stored the first income character and the rest will be eliminated,if it's not a array.
I am still attempting to figure out the reason.
int a;
a=printf("ABC");
will cause a equal 3. Then I am curise that if I use this new thing with char ,what the result will be. So I do a test
char a;
a=printf("ABC");
There is no suprise for the result. It prints ABC. But another question came to my mind. Why it prints ABC instead of just A? I remember that a char can only be stored the first income character and the rest will be eliminated,if it's not a array.
I am still attempting to figure out the reason.
Subscribe to:
Posts (Atom)