今天我們主要說的還是C的基礎,這次我們主要由代碼來具體說明。
首先來說說最頭疼的問題a=i++與a=++i的區別,a=i++是先賦值再自增,a=++i是先自增再賦值
int i = 5;
int b = i++;
int c = i;
printf("b = %d\n",b);
printf("c = %d\n",c);
int a = ++i + (b++);
printf("a = %d\n",a);
printf("b = %d\n",b);
int d = i+b;
printf("d = %d\n",d);
printf("**********************\n");
int z=1;
int j =z++;
//j=1 z=2
printf("z = %d",z);
printf("j = %d\n",j);
j = ++z;
//j=3 z=3
printf("z = %d",z);
printf("j = %d\n",j);
j = z--;
//j=3 z=2
printf("z = %d",z);
printf("j = %d\n",j);
j = --z;
//j=1 z=1
printf("z = %d",z);
printf("j = %d\n",j);
printf("**********************\n");
任何語言都會用到判斷的,下面先說說if else
printf("**********************\n");
i = 0;
if(i){
printf("true\n");
}else{
printf("false\n");
}
printf("**********************\n\n\n\n\n");
不使用中間值判斷三個數最大的
printf("**********************\n\n\n\n\n");
a = 8;
b = 4;
c = 1;
int max = 0;
if(a>b){
if(a>c){
max = a;
}else{
max = c;
}
}else{
if(b<c){
max = c;
}else{
max = b;
}
}
printf("最大:%d\n",max);
printf("**********************\n\n\n");
switch語句
printf("**********************\n\n\n");
char char_grade;
printf("請輸入:");
//scanf("%c",&char_grade);
switch(char_grade){
case 'A':
printf("90-100\n");
break;
case 'B':
printf("80-90\n");
break;
case 'C':
printf("70-80\n");
break;
default:
printf("請重新輸入輸入:\n");
break;
}
printf("**********************\n\n\n");
作者 10-3G-程龍