标签: function-call

Java 中的列表作为输出参数

我正在尝试编写一个以 List 对象作为输出参数的 Java 函数。

boolean myFunction(int x, in y, List myList)
{
    /* ...Do things... */
    myList=anotherList.subList(fromIndex, toIndex);
    return true;
}
Run Code Online (Sandbox Code Playgroud)

在此之前,我调用函数,声明 myList 如下:

List myList=null;
Run Code Online (Sandbox Code Playgroud)

然后我调用该函数

myFunction(x,y,myList)
Run Code Online (Sandbox Code Playgroud)

但是当我尝试操作 myList 时,我发现 myList 仍然为空。

我确信anotherList我的函数代码中的变量不为空,并且我确信该subList函数返回一个非空列表。

原因是什么?如何在 Java 函数中传递 List 作为输出参数?

java list function-call output-parameter

4
推荐指数
1
解决办法
4572
查看次数

如何使用 PHP 关联数组作为函数调用参数?

假设有一个带有一些参数的函数,并且我有一个关联数组(或一个具有公共属性的简单对象 - 这几乎是相同的,因为我总是可以使用类型转换(object)$array),其键对应于函数参数名称及其值对应于函数调用参数。我如何调用它并将它们传递到那里?

\n
<?php\nfunction f($b, $a) { echo "$a$b"; }\n// notice that the order of args may differ.\n$args = ['a' => 1, 'b' => 2];\ncall_user_func_array('f', $args); // expected output: 12 ; actual output: 21\nf($args); // expected output: 12 ; actual output: \xe2\x86\x93\n// Fatal error: Uncaught ArgumentCountError:\n// Too few arguments to function f(), 1 passed\n
Run Code Online (Sandbox Code Playgroud)\n

php associative-array parameter-passing function-call

4
推荐指数
1
解决办法
1271
查看次数

将数组作为函数参数传递而不定义变量

我们如何将数组直接传递给 C 中的函数?

例如:

#include <stdio.h>

void function(int arr[]) {};

int main(void) {
    int nums[] = {3, -11, 0, 122};
    function(nums);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

除了这个,我们可以写一些类似的东西function({3, -11, 0, 122});吗?

c arrays parameter-passing function-call

4
推荐指数
1
解决办法
1324
查看次数

在 C 语言中使用“{}”进行转换有什么好处?

我试图理解为什么在 ProcessHacker 代码中使用这种铸造风格。

 RtlSetHeapInformation(
            PhHeapHandle,
            HeapCompatibilityInformation,
            &(ULONG){ HEAP_COMPATIBILITY_LFH }, // HEAP_COMPATIBILITY_LFH = 2UL 
            sizeof(ULONG)
            );
Run Code Online (Sandbox Code Playgroud)

使用“{}”进行转换有什么好处?它适用于 C 和 C++ 吗?

&(ULONG){ HEAP_COMPATIBILITY_LFH }, // HEAP_COMPATIBILITY_LFH = 2UL 
Run Code Online (Sandbox Code Playgroud)

c c++ literals compound-literals function-call

4
推荐指数
2
解决办法
166
查看次数

我的阶乘函数不返回阶乘

我无法找出为什么我的函数仅返回用户输入而不是输入的阶乘。

#include <stdio.h>
#include <math.h>
int factorial(int x)
{
    //int x;
    int sum = 1;
    while (x!=0){
        sum = sum * x;
        x--;
    }
    return sum;
}

int main(){
    int x;
    printf("Enter value of x: ");
    scanf("%i",&x);
    factorial(x);
    printf("sum is %i", x);
    
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c return-value factorial function-call function-definition

4
推荐指数
2
解决办法
325
查看次数

如何在php中使用默认参数

我想定义一个doSomething(arg1, arg2)默认值为arg1 = val和arg2 = val 的函数

当我写作

function doSomething($arg1="value1", $arg2="value2"){
 // do something
}
Run Code Online (Sandbox Code Playgroud)

现在是否可以使用默认的arg1和arg2 ="new_value2"调用doSomething

php default-value function-call

3
推荐指数
2
解决办法
5182
查看次数

论函数调用中的异常安全性

f()异常安全的调用吗?

inline std::auto_ptr<C> auto_new() {
   return std::auto_ptr<C>(new C());
}

void f(std::auto_ptr<C> p1,
       std::auto_ptr<C> p2);

// ...
{
    f(auto_new(), auto_new());
}
Run Code Online (Sandbox Code Playgroud)

换句话说,auto_new()如果两个函数是内联的,那么当涉及到第一个和第二个函数调用的原子性时,它会有什么不同吗?

c++ function-call exception-safety

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

如何调用模板(ShadowDOM)中包含的其他元素的函数?

问题很简单(我希望如此).有没有办法从my-elementB调用my-elementA的函数myFunctA?或者任何与公共函数在Java或C中的工作方式类似的解决方案?

<polymer-element name="my-elementA">  
 <template>  
 ...  
 </template>

 <script>
 Polymer({

   myFunctA : function()
   {
   ...
   }

 });
</script>
</polymer-element>

<polymer-element name="my-elementB">  
 <template>
   <my-elementA></my-elementA>  
   ...  
 </template>

 <script>
 Polymer({

   myFunctB : function()
   {
   //call myFunctA()
   }

 });
</script>
</polymer-element>
Run Code Online (Sandbox Code Playgroud)

function-call polymer

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

为什么我会调用函数名称包含在parens中的函数?

我最近遇到的代码看起来像这样:

void function(int a, int b, int c){
  //...
}

int main(){
  //...
  (function)(1,2,3);
  //...
}
Run Code Online (Sandbox Code Playgroud)

在parens中单独包装函数名称有什么意义?
它有什么不同的影响function(1,2,3);吗?

为什么语言允许这样的语法?

c++ syntax function parentheses function-call

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

我怎样才能使字符串数组用交换函数交换它的组件?

问题是这段代码不会交换这两个字符串.我是编程的新手,但我可以说问题是交换功能,但我不知道如何解决它.

我试图在交换中添加strcpy而不是"="但是没有用.

#include <stdio.h>
#include <stdlib.h>

void swap(char *t1, char *t2) {
    char *t;
    t=t1;
    t1=t2;
    t2=t;
}
int main() {
    char *s[2] = {"Hello", "World"};
    swap(s[0], s[1]);
    printf("%s\n%s", s[0], s[1]);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c swap pass-by-value function-call

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