iPhone第二天之C基础
来源:网络 责任编辑:栏目编辑 发表时间:2013-07-01 05:17 点击:次
今天我们主要说的还是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;
}
}&n
首先来说说最头疼的问题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;
}
}&n
相关新闻>>
- 发表评论
-
- 最新评论 更多>>