12月3号 命名规范和运算符的使用

//命名规范

(大小写字符、数字、下划线_)

必须是字母开头

当有多个单词组成的变量名中,第一个单词小写  第二个单词首字母大写

能够见名知义

 

//声明一个变量:系统不会立刻分配内存空间

//定义一个变量:立刻分配内存空间,然后将值保存

 

printf向终端输出

  输出的是字符串 printf("");

 向终端输出:"It's delicious ?",she asked!

 要用到转义字符 \

scanf 从终端接收输出

   1.输入的内容必须是严格按照scanf内部的格式输入

   int  a,b;

   scanf("%d %d", &a, &b);

   输出格式

   12 34

  

   int  a,b;

  scanf("%d&%d", &a, &b);

  输出格式

  12&34

 

2.scanf参数必须是变量的地址(&表示地址)

  scanf("%c", &operation);

 

getchar() 从终端一次接收一个字符

 

 

运算符

+ - *

取整

    int average = totalCake / totalMan;

    int left = totalCake % totalMan;

   printf("%d cakes for %d man, each man get %d, %d left!\n",totalCake, totalMan, average, left);

类型的优先级 short->int->long->float->double

 

类型转换分为两种

//强制转换(float) totalCake

float result = (float)totalCake / totalMan;

//自动转换

float result = 1.0*totalCake / totalMan;

 

     /* 

     ++   自动+1

     a++  延迟+1,当语句执行完毕之后再加1

     ++a  立刻+1

     */

    int temp = 10;

    int re = (temp++) + 20;

 

    printf("%d\n", re);    

    printf("temp = %d\n", temp++);  

    printf("after temp = %d\n", temp);   

    printf("temp = %d after = %d\n", temp++, temp);  

    

    int a = 20;

    int b = (++a) + 20;

    printf("a=%d b=%d\n", a, b);

 

posted @ 2015-12-03 18:40  南城半夏北风过丶  阅读(189)  评论(0编辑  收藏  举报