大家可以敲写一下下面的练习代码,看下运行结果,都很简单,关键要理解。
if:
# include <stdio.h> int main(void) { int i = 1; i = i + 1; if(i>10); i = 1; printf("%d\n", i); return 0; }
if示例2:
# include <stdio.h> int main(void) { int i; if (1 > 2) printf("哈哈!\n"); else if (2 > 5) printf("嘿嘿!\n"); else if (2 > 2) printf("skdf"); else i = 1 > 2; printf("i = %d", i); return 0; } /* 总结: 即便有多个表达式成立,也只会执行第一个成立的表达式 */
scanf示例1:
# include <stdio.h> int main(void) { int i, j, k; //printf("请输入:i的值"); scanf("%d %d %d", &i, &j, &k); printf("i = %d\nj = %d\nk = %d\n", i, j, k); return 0; }
scanf示例2:
# include <stdio.h> int main(void) { int i; char ch; printf("请输入i的值:i="); scanf("%d", &i); printf("结果是:i=%d\n", i); while ((ch=getchar())!='\n') continue; int j; printf("请输入j的值:j="); scanf("%d",&j); printf("结果是:j=%d\n", j); return 0; }
浮点数的存储:
# include <stdio.h> int main(void) { float x = 66.6; printf("x = %f\n", x); return 0; }
bool变量:
# include <stdio.h> int main(void) { bool i; i = true; //1为真,0为假。 printf("%d\n", i); return 0; }
取地址符&:
# include <stdio.h> int main(void) { double i = 12314; printf("%#X\n", &i); //以十六进制形式输出变量i的地址 return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/lfhappypain/article/details/47187625