标签: function-call

为什么列表变量有时不受函数更改的影响,因为我认为 python3 可以通过引用传递列表变量?

对于python3,我最初需要从列表中提取奇数和偶数位置并将其分配给新列表,然后清除原始列表。我认为列表会受到通过“通过引用传递”的函数调用的影响。测试一些场景,它有时会起作用。有人可以解释一下python3在这里是如何工作的吗?

情况 1:空列表按预期填充字符串。

def func1(_in):
    _in.append('abc')

mylist = list()
print(f"Before:\nmylist = {mylist}")
func1(mylist)
print(f"After:\nmylist = {mylist}")
Run Code Online (Sandbox Code Playgroud)

输出情况 1:

Before:
mylist = []
After:
mylist = ['abc']
Run Code Online (Sandbox Code Playgroud)

情况 2:中间列表元素按预期替换为字符串。

def func2(_in):
    _in[1] = 'abc'

mylist = list(range(3))
print(f"Before:\nmylist = {mylist}")
func2(mylist)
print(f"After:\nmylist = {mylist}")
Run Code Online (Sandbox Code Playgroud)

输出情况2:

Before:
mylist = [0, 1, 2]
After:
mylist = [0, 'abc', 2]
Run Code Online (Sandbox Code Playgroud)

案例3:为什么函数调用后列表不为空?

def func3(_in):
    _in = list()

mylist = list(range(3))
print(f"Before:\nmylist = {mylist}")
func3(mylist)
print(f"After:\nmylist = {mylist}")
Run Code Online (Sandbox Code Playgroud)

输出案例3:

Before:
mylist = [0, 1, 2]
After: …
Run Code Online (Sandbox Code Playgroud)

list pass-by-reference function-call python-3.x empty-list

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

函数中的 C 数组指针

我写了这个函数:

int einmaleins(int zahl, int *arr){
int e;
for(int i = 1; i<11; i++){
    e = zahl*i;
    arr[i-1]=e;
}

return 0;
}

int main(){
int arr[10] = {0};
einmaleins(2, &arr[10]);

return 0;
}
Run Code Online (Sandbox Code Playgroud)

问题是指针数组,但是当我启动程序时,我收到以下消息:*** 检测到堆栈粉碎 ***:终止

我真的不知道该怎么办。

c arrays pointers function-call implicit-conversion

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

为什么将 4 元素数组传递给 C 中的函数时会出现警告?

如果有一个大小为 4 的数组,则将该数组的值发送给函数。为什么会出现警告?

#include <stdio.h>
#include <stdbool.h>

void greatestOf(int arr[], int *result) {
    *result = arr[0];

    for (int i = 1; i < 4; i++) {
        if (arr[i] > *result) {
            *result = arr[i];
        }
    }
}


int main() {
    int arr[4], x;
    printf("Input : ");
    scanf("%d %d %d %d", &arr[0], &arr[1], &arr[2], &arr[3]);

    greatestOf(arr[4], &x); // here warning text. When I try to use '''greatest(arr, &x)'''

    printf("Greatest number: %d\n", x);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我收到以下警告消息:

#include <stdio.h>
#include <stdbool.h>

void …
Run Code Online (Sandbox Code Playgroud)

c arrays arguments function function-call

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

如何在Python中同步函数调用的时间戳?

我在模块中有一个读取功能.

如果我同时执行该功能,我需要为其加时间戳.

我该怎么做呢?

python function-call timestamping simultaneous-calls

-1
推荐指数
1
解决办法
1262
查看次数

接收C中的函数调用

为什么这个递归函数落入无限循环?它显示Val的价值没有下降.背后的逻辑是什么?

int Bar(int Val) // value passed is 3
{
    int x=0;
    while (Val>0)
    {
        x=x+Bar(val-1);
    }
    return Val
}
Run Code Online (Sandbox Code Playgroud)

c recursion function-call

-1
推荐指数
1
解决办法
78
查看次数

在方案中显示和返回内容的程序?

我希望我的程序打印一些东西,然后返回那个东西。我试过这个

(define (print x)
    ((display x)
     x))
Run Code Online (Sandbox Code Playgroud)

不是应该直接说这个过程x首先显示然后返回它,就像它在过程结束时所表达的那样吗?好吧,显然这是错误的,而且我对Scheme 有一些非常基本的了解。所以任何人,帮助我理解这一点。谢谢

syntax scheme function definition function-call

-1
推荐指数
1
解决办法
159
查看次数

为什么我们在调用一些函数时放 () 而有些我们在 python 中没有?

df.shape #we check the shape of dataset
(1338, 7)
Run Code Online (Sandbox Code Playgroud)

在调用上述形状函数时,我们没有使用 (),但对于大多数其他函数,我们使用 ()。这是为什么?

df.info()# gives the info of the dataset 
Run Code Online (Sandbox Code Playgroud)

python function function-call python-3.x

-1
推荐指数
1
解决办法
42
查看次数

为什么这是以下 c 代码 12 的输出?

这是一个简单的 c 程序,但输出是 12 我不明白相同的输出是 12。请解释一下

#include <stdio.h>
    int show() 
    {
        printf("hello world\n");
    }
    int main() 
    {
        int i;
        i=show();
        printf("%d",i);
      
        return 0;
    }
Run Code Online (Sandbox Code Playgroud)

c return-value function-call

-1
推荐指数
1
解决办法
47
查看次数

不同文件中的函数无法正常工作

我做了一个调用这个函数的程序.我知道这是因为"Int Strength已被调用"出现在输出框中.但是,它不会改变我告诉它要做的值.我希望它从main()获取整数值,然后使用它们并返回新值.我使用的头文件只包含"int strength(int a,int s,int i)"

int strength(int a, int s, int i)
{
    using namespace std;
    cout << "Int Strength has been called" << endl;
    a = a + i;
    s = s - i;
    return a;
    return s;
}
Run Code Online (Sandbox Code Playgroud)

c++ function-call

-2
推荐指数
1
解决办法
61
查看次数

与函数调用混淆

为什么这个函数调用有效?该函数func(int,int)被声明为采用整数,但即使用double调用它也是有效的.为什么会这样?

#include<iostream>
using namespace std;


void func(int a,int b){


cout<<"a is "<<a;
cout<<"\nb is "<<b;

}

int main(){
func(12.3,34.3);


}
Run Code Online (Sandbox Code Playgroud)

c++ function-call

-2
推荐指数
1
解决办法
87
查看次数

如何在c中将void函数(void)作为参数传递给另一个函数

[在此处输入图像描述][1]我有一个void readline()输出字符串的函数,我想将其作为参数传递给另一个函数,我该怎么做,

谢谢你的帮助。

int scorecount(argc1, argv1, void readline());
void readline();


int main(int argc, char *argv[]){
    scorecount(argc,argv);
}


int scorecount(argc1, argv1, void readline()){

    output a int
    and I want to use the string from readline function somewhere in
    scorecount

}


void readline(){

    output a string

}
Run Code Online (Sandbox Code Playgroud)

c parameters function-call function-declaration

-5
推荐指数
1
解决办法
2473
查看次数