鱼C论坛

 找回密码
 立即注册
查看: 2382|回复: 2

求指针的运用

[复制链接]
发表于 2012-2-25 20:21:43 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. #include <stdio.h>
  2. #define SIZE 10
  3. int sump (int * start, int * end);
  4. int main (void)
  5. {
  6.         int marbles [SIZE]= {20, 20, 20, 20, 20, 20, 20, 20, 20, 20};
  7.         long answer;
  8.         answer = sump (marbles, marbles + SIZE);
  9.         printf("The total number of marbles is %ld.\n", answer);
  10.         return 0;
  11. }
  12. int sump (int * start, int * end)
  13. {
  14.         int total = 0;
  15.         for ( ;  start <  end;  start++) //这里为什么不用 *号?
  16.                 total += *start;             //这里要用*号?
  17.         return total;
  18. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2012-2-25 20:25:34 | 显示全部楼层
*start 是指向它地址里的值吗?不带*号是不是指这个参数所占的内存大小?
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2012-2-25 21:00:49 | 显示全部楼层
#include <stdio.h>
#define SIZE 10
int sump (int * start, int * end);
int main (void)
{
        int marbles [SIZE]= {20, 20, 20, 20, 20, 20, 20, 20, 20, 20};
        long answer;
        answer = sump (marbles, marbles + SIZE);
        printf("The total number of marbles is %ld.\n", answer);
        return 0;
}
int sump (int * start, int * end) //指针存储是一个地址。如0000005等。
{                                          //所以start=0000005;而*start等于0000005所存的值。
        int total = 0;
        for ( ;  start <  end;  start++) //这里为什么不用 *号?//这里的start和end是地址值,不用*号
                total += *start;             //这里要用*号? //而*start是地址所存的值每个为20。
        return total;
}
小甲鱼最新课程 -> https://ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-11-11 15:55

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表