相关疑难解决方法(0)

如何从被调用的函数中更改调用函数中的变量?

如何try()修改函数(以及它的调用)以从下面的程序中获得11的输出?

#include <stdio.h>

/* declare try() here */

int main(void)
{
    int x = 10;
    try();              /* Call can change */
    printf("%d\n", x);
    return 0;
}

void try()              /* Signature can change */
{
    /* how to change x here?? */
}
Run Code Online (Sandbox Code Playgroud)

c

7
推荐指数
2
解决办法
2万
查看次数

为什么函数不会改变变量?

在这段代码中,我似乎得到零,我不太熟悉为什么我不能用我创建的函数改变变量长度.任何帮助都可能有用.

     #include <stdio.h>
double get_length(double a);
int main(int argc, char* argv[])
{
    double length = 0;
    get_length(length);
    printf("%lf", length);
    return 0;
}
double get_length(double a)
{
    printf("What is the rectangle's length?\n");
    scanf("%lf", &a);
    return a;
}
Run Code Online (Sandbox Code Playgroud)

打印时,返回0.0000

c double return function

0
推荐指数
1
解决办法
107
查看次数

标签 统计

c ×2

double ×1

function ×1

return ×1