首页 > 代码库 > IOS开发培训一月十三日笔记
IOS开发培训一月十三日笔记
//
//
// main.c
// LessonHelloWorld
//
// Created by lanouhn on 15/1/12.
// Copyright (c) 2015年 lanouhn. All rights reserved.
//
//单行注释
//单行注释的快捷键:command+/
/*
多行注释
*/
//注释不参与程序的编译
//代码→编译→可执行文件(.exe)
//引用C语言的标准输入库
#include <stdio.h>
//主函数,程序的入口
int main(int argc, const char * argv[]) {
// insert code here...
printf("Hello, World!\n");
return 0;
}
//快捷键
//编译的快捷键:command+B
//编译+运行:command+R˜
// main.m
// LessonBasic
//
// Created by lanouhn on 15/1/13.
// Copyright (c) 2015年 lanouhn. All rights reserved.
//
//command+Z:撤销
//command+alt+[ 或 ]:代码上下移动
//数据类型
//作用
//1,规定容器存储的大小
//2,规定容器内存放的数据类型
//分类
//1,整型:char(字符型),short(短整型),int(整型),long(长整形)
//2,浮点型:float(单精度浮点型),double(双精度浮点型)
//常量:程序运行期间不能改变的量
//整型常量:100,999,
//字符常量:‘A’,‘B‘
//浮点型常量:3.14,0.01
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
printf("Hello, World!");
//变量:程序运行期间可以改变的量
//变量是一个容器,能够改变的是容器的内容
//变量的定义
//数据类型 变量名=初值
//变量命名规范
//1,必须以数字,字母,下划线组成,并且不能以数字开头
//2,见名知意
//3,不能重名
//4,不能使用系统关键字
//5,使用驼峰法命名(大驼峰法和小驼峰法)
int appleCount = 0;//(小驼峰法)
int a =0;
short floor = 5;
int roomNumber = 432;
printf("a\n");
printf("输出a的值\n");
printf("%d\n", a);
//当数据类型相同的变量,可以用逗号隔开:int a = 0,appleCount = 0
char number = ‘A‘;
printf("number = %c\n", number);
//打印字符对应的ASCII值(十进制数)
printf("number = %d\n", number);
//打断点时,应打在想要执行的代码下一行
short s = 12;
printf ("i = %hd\n", s);
int i = 100;
printf("i = %d\n", i);
long l = 1234567890;
printf ("l = %ld\n", l);
//单精度,小数点后六位是有效位数
float f = 1.1235678923456789123456789;
printf("f = %.20f\n", f);
//双精度,小数点后15位是有效位数
double d = 1.123456789123456789123456789;
printf ("d = %.20f\n", d);
//print:打印
//f:function,函数
int num1 = 1, num2 = 2;
printf("num = %d, num = %d\n", num1, num2);
//回车:\n
//tab:\t 相当于四个空格
//百分号:%%
//引号:\"
printf("1\n23\t45%%67\"89");
//格式控制符
int style = 123;
printf("%5d\n", style);
printf("%05d\n", style);
printf("%-5d\n", style);
float fl = 123.12356789;
printf("%f\n", fl);
printf("%9f\n", fl);
printf("%15f\n", fl);
printf("%15.9f\n", fl);
printf("%015.9f\n", fl);
//printf("%-015.9f\n", fl);
//-:左对齐,默认右对齐
//0:位数不够补0
//15:输出的位宽,不足默认补空格
//.9:小数点后的位数
//交换两个变量的值
int a1 = 3;
int a2 = 5;
printf("a1 = %d\n, a2 = %d\n", a1, a2);
//借助第三个变量交换
int temp = 0;
temp = a1;
a1 = a2;
a2 = temp;
printf("a1 = %d\n, a2 = %d\n", a1, a2);
//不借助第三个变量交换
a1 = a2 - a1;
a2 = a2 - a1;
a1 = a1 + a2;
printf("a1 = %d\n, a2 = %d\n", a1, a2);
//运算符
//1,赋值运算符:=
//把等号右侧的值赋给等号左侧:
int m = 1;
int n = 2;
//2,算术运算符
//加:
int sum = 0;
sum = m + n;
//减:
int minus = 0;
minus = n - m;
//乘:
int mul = 0;
mul = n * m;
//除:
//整数相除,小数点后的值会被忽略掉
int div = 0;
div = n / m;
printf("div = %d\n", div);
int div1 = 3.0/2;
printf("div = %d\n", div);
//如果算出是1.5,要保证除号两侧至少有一个是浮点数
//取余
//一般只对整数取余
//被除数 / 除数 = 商
//除数不能为零
int rem = 0;
rem = n % m;
printf("rem = %d\n", rem);
//自增 ++n , n++
n++;
++n;
//相当于n = n + 1;
//自减
m--;
--m;
//相当于m = m - 1;
//原则:
//1,++或--在前,先+1或-1,再运算
//2,++或--在后,先运算,再+1或-1
/*
int j = 5;
int k = 0;
k = j++;
//k = j
//j = j + 1
printf("k = %d\n, j = %d\n", k, j);
k = ++j;
//j = j + 1
//k = j
printf("k = %d\n, j = %d\n", k, j);
*/
/*
int j = 2;
int k = 3;
int c = 0;
//运算符优先级
c = j +(++ k);
printf("j = %d\n, k = %d\n, c = %d\n", j, k, c);
*/
/*
//复合运算符
int k = 5;
int j = 0;
j += k;//j = j + k
j -= k;//j = j - k
j *= k;//j = j * k
j /= k;//j = j / k
j %= k;//j = j % k
*/
/*
int x = 1, y = 2, z = 3;
int c = 10,k = 0;
x +=(++y);
y = x++;
z = x / y;
c %= y;
k = ++c;
printf("x = %d\n, y = %d\n, z = %d\n, c = %d\n, k = %d\n", x, y, z, c,k);
*/
//表达式:有常量,变量,运算符组成的:例如 x+1,y+1
//语句:程序执行的最小单元,以分号(;)结束:例如:(x + 1;),(y + 1;)
//以分号计算语句的数量
//输入函数:scanf
int g = 0;
printf("请输入一个整数");
//当遇到scanf,程序会等待用户在控制台输入
//确定输入,需要用大回车
scanf("%d", &g);
printf("g = %d\n", g);
//代码规范:
//双目运算符左右两侧要加空格
//单目运算符不需要加空格
//逗号后边加空格
return 0;
}
IOS开发培训一月十三日笔记