《Programming Abstractions In C》学习第42天,p76-p73总结。
一、技术总结
1.数组和指针
在C语言中,数组和指针非常相似,相似到必须将它们同时考虑,当看到数组就应该想到指针,当看到指针就应该想到数组。示例:
#include <stdio.h>
int SumIntegerArray(int array[], int n);
int SumIntegerArray2(int *array, int n);
/*
* SumIntegerArray:数组求和,数组用法
*/
int SumIntegerArray(int array[], int n) {
int i, sum;
sum = 0;
for (i = 0; i < n; i++) {
sum += array[i];
}
return sum;
}
/*
* SumIntegerArray2:数组求和指针用法
*/
int SumIntegerArray2(int *ip, int n) {
int i, sum;
sum = 0;
for (i = 0; i < n; i++) {
sum += *ip++;
}
return sum;
}
void main() {
int aSum, pSum;
int array[] = {1, 2, 3, 4, 5};
aSum = SumIntegerArray(array, 5);
printf("对数组[1, 2, 3, 4, 5]求和: aSum=%d\n", aSum);
pSum = SumIntegerArray2(array, 5);
printf("对数组[1, 2, 3, 4, 5]求和: pSum=%d\n", aSum);
}
那么数组和指针有什么不同呢?声明的时候内存分配不一样。示例:
#include <stdio.h>
void main() {
int array[5];
int *p;
printf("%lu\n", sizeof(array)); //20, int类型占4bytes,5个元素占20个bytes
printf("%lu\n", sizeof(p)); //8, 64位的电脑
}
二、英语总结
1.difference和distinctiond的区别?
答:网上查找了一番,对于各种回答还是不大满意,先记着:
(1)stack exchange:
“Difference” is a much more generic work just referring to set of attributes that are different between two or more things in a set. “Distinction” is much more specific and often separates ONE item above and beyond the other differences in a set. E.g:All people have differences, but some have the distinction of being famous.
三、参考资料
1.编程
1)Eric S.Roberts,《Programming Abstractions in C》:https://book.douban.com/subject/2003414
2.英语
1)Etymology Dictionary:https://www.etymonline.com
2)Cambridage Dictionary:https://dictionary.cambridge.org
3)Merrian-Webster Dictionary:https://www.merriam-webster.com
4)Collins Dictionary:https://www.collinsdictionary.com
5)Oxford Dictionary:https://www.oxfordlearnersdictionaries.com
6)The Free Dictonary:https://www.thefreedictionary.com
7)Urban Dictionary:https://www.urbandictionary.com