写点什么

Programming abstractions in C 阅读笔记:p76-p83

作者:codists
  • 2023-08-08
    广东
  • 本文字数:1096 字

    阅读完需:约 4 分钟

《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


欢迎搜索及关注:编程人(a_codists)

发布于: 刚刚阅读数: 4
用户头像

codists

关注

公众号:编程人 2021-01-14 加入

Life is short, You need Python

评论

发布
暂无评论
Programming abstractions in C阅读笔记:p76-p83_codists_InfoQ写作社区