小编Jon*_*cki的帖子

C 简介 - 如何在函数中通过引用传递参数?

我正在做我的 C 入门课程作业,我的任务是以下......

  1. 为一个函数编写代码,该函数通过值接收两个参数(a 和 b),并通过引用还有两个参数(c 和 d)。所有参数都是双倍的。
  2. 从 main 中,使用 scanf 获取两个数字,然后调用该函数,然后将两个返回值显示到 printf 语句中的输出。
  3. 该函数的工作原理是将 (a/b) 分配给 c 并将 (a*b) 分配给 d。

虽然我的知识很基础,但我相信我理解主要内容

      //first and second double hold the scanf inputs
      double first;
      double second;

      //unsure here - to reference c and d as parameters in the function, do I simply declare unfilled double variables here?
      double *c;
      double *d;

   printf("Enter your first number\n");
   scanf("%f\n", &first);
   printf("Enter your second number\n");
   scanf("%d\n", &second);

   //call the function, first and second by …
Run Code Online (Sandbox Code Playgroud)

c pointers function pass-by-reference

3
推荐指数
1
解决办法
2072
查看次数

标签 统计

c ×1

function ×1

pass-by-reference ×1

pointers ×1