ASCII code
int main() {
printf("%d, %c\n", '0', '0');
printf("%d, %c\n", '0' + 3, '0' + 3);
return 0;
}
/**
print:
48, 0
51, 3
---------------------------------------------------------------------------------
'0' 是一个字符,它的ASCII码为48
'0' + 3 先把'0'转换为ASCII码(即48),48 + 3 = 51,然后把51转化为字符(即3)
**/
static variation (静态变量)
int main() {
int function(int);
int i;
for (i = 1; i <= 5; ++i) {
printf("%d, ", function(i));
}
return 0;
}
int function(int n) {
static int f = 1;
f *= n;
return f;
}
/**
print:
1, 2, 6, 24, 120,
--------------------------------------------------
关键字 static
1. 并不是function()的一部分(在function() 里面声明只是为了在function() 中可见)
2. 只在编译function() 时初始化一次,若没有显示的初始化,将被初始化为0。
3. 初始化一次(编译时执行),它不是在运行时执行的语句
**/
sizeof()
int main() {
float temp[N] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
printf("the size of 'temp[0]' is %d\n", sizeof (temp[0]));
printf("the size of 'temp' is %d\n", sizeof(temp));
return 0;
}
/**
print:
the size of 'temp[0]' is 4
the size of 'temp' is 40
------------------------------------------------------
sizeof() 指在内存中所占的大小
**/
++i, i++
#define N 10
int main() {
int i;
char a[N] = "abc";
for (i = 0; a[i] != '\0'; ) {
printf("%d, %c\n", a[i++], a[i]);
}
putchar('\n');
for (i = 0; a[i] != 0; ) {
printf("%d, %c\n", a[++i], a[i]);
}
getchar();
return 0;
}
/**
print:
97, a
98, b
99, c
98, a
99, b
0, c
---------------------------------------------------
i++ 先输出i,再自加
++i 先自加,后输出i
**/