C 语言笔记:数组与下标
111 字
1 分钟
C 语言笔记:数组与下标
数组下标从 0 开始。长度为 n 的数组,其有效下标为 0 到 n - 1。遍历条件应该写成 i < n。
#include <stdio.h>
int main(void) { int scores[] = {82, 91, 76}; size_t count = sizeof scores / sizeof scores[0];
for (size_t i = 0; i < count; ++i) { printf("%d\n", scores[i]); } return 0;}这里的 sizeof 写法适用于仍然是数组的变量。数组作为函数参数传递时,通常应把元素个数也传进去。
文章分享
如果这篇文章对你有帮助,欢迎分享给更多人!

