标签: comma-operator

C++ 用于使用逗号运算符的多个控制语句

如果在“for 循环”中使用逗号运算符来编写多个控制语句,它如何?我试过

#include <iostream>

using namespace std;

int main() {
        for (int x = 0, y = 0; x < 3, y < 4; ++x, ++y) {
                cout << x << " " << y << endl;
        }
        return 0;
}

Run Code Online (Sandbox Code Playgroud)

似乎只计算最后一个表达式。泰

c++ for-loop comma-operator

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

这个逻辑是如何工作的: k+=(x=5,y=x+2,z=x+y) ;

这个逻辑是如何工作的: k+=(x=5,y=x+2,z=x+y);

它将如何给出结果 k == 22。当我初始化 k = 10 的值时

#include <stdio.h>
int main()
{
    int x,y,z,k=10;
    k+=(x=5,y=x+2,z=x+y);
    printf("value of k %d ",k); //why it will show value of k =22
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c comma-operator assignment-operator

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

List context and the comma operator in Perl

Having some significant confusion about what it means to "evaluate in list context", specifically related to the comma operator. In the linked perlop doc, it says: In list context, it's just the list argument separator, and inserts both its arguments into the list. However, the code

@y = 9, 8, 7, 6;
say @y, ', ', scalar @y;
Run Code Online (Sandbox Code Playgroud)

gives output 9, 1. This respects the fact that, when used as a binary operator on scalar values (?), the …

perl scalar list operator-precedence comma-operator

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

逗号运营商作为回报

我正在从一个页面阅读JS,这是我发现的(源代码由google chrome dev工具进行反混淆):

var db = function(a) {
    return a.replace(/[^\w\s\.\|`]/g, 
    function(b) {
        return "\\" + b
    })
};
Run Code Online (Sandbox Code Playgroud)

第一个逗号运算符操作数(a.replace()一个)有一些技巧吗?

从我的角度来看,该a.replace(/[^\w\s\.\|``]/g,部分是完全冗余的,可以删除.

我错过了什么吗?

javascript comma-operator

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

汇编中的逗号 (,) 运算符是什么?

这是我编写的一个简单的汇编语言程序:

section .text
    global main     ;must be declared for linker (ld)
main:               ;tells linker entry point
    mov edx,len     ;message length
    mov ecx,msg     ;message to write
    mov ebx,1       ;file descriptor (stdout)
    mov eax,4       ;system call number (sys_write)
    int 0x80        ;call kernel

    mov eax,1       ;system call number (sys_exit)
    int 0x80        ;call kernel

section .data
msg db 'Hello, world!', 0xa  ;our dear string
len equ $ - msg              ;length of our dear string
Run Code Online (Sandbox Code Playgroud)

现在我不知道这一行发生了什么:msg db 'Hello, world!', 0xa
我知道的含义,msg db 'Hello, …

assembly comma-operator

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

这个语句如何工作`int k =(a ++,++ a);`在c或c ++中

我无法理解下面代码的输出是如何"-3"的?

#include <stdio.h>
void main()
{
    int a = -5;
    int k = (a++, ++a);
    printf("%d\n", k);
}
Run Code Online (Sandbox Code Playgroud)

int k = (a++, ++a);在c或c ++中这个陈述背后的概念是什么 ?

c c++ initialization comma comma-operator

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

C语言中逗号运算符的行为

如果我使用逗号运算符编写代码,如下所示:

int i;
i = 5, i++, i++;
Run Code Online (Sandbox Code Playgroud)

它会调用未定义的行为吗?

c comma-operator

0
推荐指数
2
解决办法
102
查看次数

函数参数中的逗号运算符

我正在阅读 GNU C 手册的摘录:

\n\n
\n

您可以使用逗号运算符来分隔两个(表面上相关的)表达式。

\n
\n\n

稍后在描述中:

\n\n
\n

如果要在函数参数中使用逗号运算符,则需要在其两侧加上括号。\xe2\x80\x99s 因为函数参数列表中的逗号具有不同的含义:它们分隔参数。

\n
\n\n

到现在为止,一切都还好。奇怪的部分是:

\n\n
\n

foo (x, (y=47, x), z);是一个只有三个参数的函数调用。(第二个参数是(y=47, x)。)

\n
\n\n

问题是:参数如何压入堆栈,如何从函数内部访问它?

\n

c expression arguments comma-operator

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

为什么它只收到1个整数?

为什么只接收一个整数?
这是代码:

#include <iostream>

int main () {
    int num1,num2,num3;
    std::cin>>num1,num2,num3;

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

c++ operator-precedence comma-operator

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

错误的数组索引不会导致错误

考虑以下程序:

#include <stdio.h>
int main(void)
{
    int a[] = {1, 2, 3};

    for (size_t i = 0; i < 3; i++)
        printf ("%i\n", a[0, i]);

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

显然,a例如在Python中,像二维数组一样访问一维数组。但是,此代码的确带有unused-value警告。我希望它会产生错误,因为我一直认为这是因为在C中多索引是完全错误的(请参见K&R第112页)。令我惊讶的是,以上代码确实打印出了数组元素。

如果将a[0, i]第六行更改为a[i, 0],则第一个数组元素将被打印3次。如果您使用a[i, 1]第二个元素,则将打印三遍。

如何将一维数组上语法错误的多索引转换为指针算术,并且a[i, 0]未使用结果的什么值?

而且,是的,我知道如何在C中进行多索引。

c arrays indexing comma-operator

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

调整矢量矢量的大小

下面是用于调整矢量矢量大小的代码块.为每行大小生成的输出打印为0?即使我将每一行调整为W,为什么会发生这种情况;

int main() {
    int H,W,i;
    cin >> H,W; // H=3,W=5;
    vector<vector<int> >v;
    v.resize(H);

    for(i=0;i<H;i++)
        v[i].resize(W);

    cout << v[1].size(); // Output is printed 0 
}
Run Code Online (Sandbox Code Playgroud)

c++ vector operator-precedence comma-operator

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

逗号运算符和赋值

考虑一下声明:

int a;
a = 1,2,3; 
cout<<a; // prints a = 1
Run Code Online (Sandbox Code Playgroud)

我咨询了这个网站.现在发生这种情况是因为comma运算符的优先级最低.所以它就像(a=1),2,3.但出于好奇,我想知道在此之后发生了什么,编译器是否忘记了剩下的数字23.因为我认为如果他们被考虑那么可能先是1然后是2然后3将被初始化为a(类似于a = (1,2,3)).请告诉我这里究竟发生了什么?

c++ operators comma comma-operator

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

在 C 中将 (2, 6, 8) 赋给一个整数是什么意思?

下面这段代码的输出是什么?为什么?

#include <stdio.h>
int main()
{
   int x = (2,6,8);
   printf("%d",x);
   return 0;
}
Run Code Online (Sandbox Code Playgroud)

c comma-operator

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