标签: operators

Javascript: false && false 是假的吗?

所以,我做了一些搜索,看起来还没有被问到,但我可能是错的。

逻辑上

false && false === true
false && true === false
true && false === false
true && true === true
Run Code Online (Sandbox Code Playgroud)

然而

似乎并非如此javascript。我在上面运行了console,这是我从 FireFox && Chrome 得到的:

false && false //console output: false
false && true //console output: false
true && false //console output: false
true && true //console output: true
Run Code Online (Sandbox Code Playgroud)

我已经找到了解决方案,但认真的?为什么?我认为这是标准行为。

它甚至在Java文档中logical AND | &&.

javascript boolean-logic operators

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

什么:?运营商在bash做什么?

我在bash文件中有这样的表达式:

MY_NEW_VAR="path/${MY_VARIABLE:?}"
Run Code Online (Sandbox Code Playgroud)

什么:?运营商意味着

bash operators

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

CS0019 C# 运算符 '||' 不能应用于“int”和“int”类型的操作数

我有一个带有整数的或运算符(||),但由于某种原因它给了我一个错误。整数是位置。我想跟踪玩家的位置,这样我就可以在一大块代码中控制所有操作。看起来像的行if (location == (1 || 2 || 3)给了我错误。

Actions:
            Console.WriteLine("");
            Console.Write("What should i do? ");
            string move = Console.ReadLine();
            if (move.Contains("north"))
            {
                if (location == (1 || 2 || 3))
                {
                    Console.WriteLine("There is a cliff here I cant climb up!");
                }
            }
            else if (move.Contains("east"))
            {
                if (location == (3 || 6 || 9))
                {
                    Console.WriteLine("There is a cliff here I cant climb up!");
                }
            }
            else if (move.Contains("south"))
            {
                if (location == (7 || 8 || 9)) …
Run Code Online (Sandbox Code Playgroud)

c# operators

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

使用与&减号运算符实现的符号(&)有什么作用?

我正在准备编程竞赛,我偶然发现了下面的问题.

void main(){
    int number, result;
    scanf("%d",&number);
    result=number-(number&-number); //this is what i'm struggling to understand
    printf("%d",result);  
}
Run Code Online (Sandbox Code Playgroud)

请注意在注释行中使用"& - ".我无法弄清楚它的功能.我尝试使用谷歌搜索和逆向工程,但我找不到任何东西.

此外,问题本身并不是关于确切的输出,因为变量"数字"是动态的.我只需要了解"& - "部分的作用.谢谢!

c operators ampersand

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

在 python 中使用 zip() 运算符时出现重复

我看到 python 中的 zip(<>) 不接受重复项。有没有办法让它考虑重复项?以下是我的两个清单:

[933, 933, 933, 933, 933, 1129, 1129, 1129, 1129]
[4139, 6597069777240, 10995116284808, 32985348833579, 32985348838375, 1242, 2199023262543, 6597069771886, 6597069776731]
Run Code Online (Sandbox Code Playgroud)

当我尝试使用 zip() 同时循环列表时,仅考虑 (933, 4139) 和 (1129, 1242) 。有没有办法(使用 zip)来避免这种情况并使其考虑列表中的所有值。

提前致谢

  • 项目清单

python list operators python-3.x

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

C# Elvis 运算符可为空的布尔值

我如何向 Elvis Operator 申请以下内容:

Exp: b= a?.attr> 0
Run Code Online (Sandbox Code Playgroud)

结果应该是:如果anullb应该是null,否则,b应该是结果attr > 0

.net c# boolean operators

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

如何解决此错误:二进制表达式('std :: vector &lt;double&gt;'和'double')无效的操作数?

我想获得一些陀螺仪读数的平均值,它涉及将一个std::vector<double>类型与一个双精度类型相除,但是出现以下错误,该错误报告

无效的二进制二进制操作数(“ std :: vector”和“ double”)

我该如何解决?


    double n_readings;
    std::vector<double> gyro_reading;
    for(int i = 0; i < n_readings; i++) {

        gyro_reading.push_back(gyro_z());
        msleep(1);

    }

    double average = gyro_reading/n_readings;
Run Code Online (Sandbox Code Playgroud)

c++ algorithm vector operators

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

不能将数组运算符用于基于数组的指针(读取访问冲突)

基本上我想要实现的是使用指针,避免new关键字来获得与其他语言相同的复制行为(=如果我们谈论对象,运算符会将右操作数的 ref 分配给左操作数,类似于shared_ptr应该提供)。如果我不使用数组运算符,我要展示的内容似乎有效[]。为什么会发生这种情况,我该如何解决?

// Declaration way before
std::vector<int>* test;

test = &std::vector<int>();
(*test)[1] = 0;
Run Code Online (Sandbox Code Playgroud)
// Declaration way before
std::map<std::string, int>* test;

test = &std::map<std::string, int>();
(*test)["a"] = 0;
Run Code Online (Sandbox Code Playgroud)

错误发生在两者的最后一行。

c++ pointers reference operators memory-address

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

使用equals和==进行比较

我有这样的条件:

try {
        History history = requestHelper.getHistory();
       if (!history.getInvoiceNo().equalsIgnoreCase("") || //String
                !history.getCcEmail().equalsIgnoreCase("") || //String
                !history.getHostAuthCode().equalsIgnoreCase("") || //String
                !history.getMerchantCategory().equalsIgnoreCase(null) || //String
                !history.getCcName().equalsIgnoreCase("") || //String
                !history.getCcPhone().equalsIgnoreCase("") || //String
                history.getBatchNo() != 0 || //int
                !history.getIpAddress().equalsIgnoreCase("") || //String
                !history.getTransactionStatus().equals(null)) { //char
            System.out.println(": : : FAILED GET HISTORY, NO PARAMETER SET!");
            requestHelper.getResultHelper().setLstHistoryTransaction(null);
       else {
            System.out.println(": : : SUCCESS GET HISTORY!");
            /* some command */
       }
} catch (Exception ex) {
        System.out.println(": : : ERROR QUERYING HISTORY TO DATABASE");
        ex.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)

但是,当我不填充该参数的任何变量时,为什么它会像这样得到错误:

10:07:35,238 INFO [STDOUT] :::错误查询历史到数据库 …

java operators

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

连接和递归

#Calculates to the index position of a fib number.
def f3(n):
    if n < 2:
        return n
    return f3(n-2) + f3(n-1)
Run Code Online (Sandbox Code Playgroud)

该函数只接受一个参数,但在返回中发送了两个参数,但是,它有效!这里发生了什么事?

如果我返回f3(n-3),则该函数会崩溃.串联有什么影响?

python recursion operators

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