comma-operator Questions

9

Solved

What does the , operator do in C?
Almonte asked 9/9, 2008 at 18:34

6

Solved

#include <stdio.h> main() { int i; for(i=0; i<0, 5; i++) printf("%d\n", i); } I am unable to understand the i<0, 5 part in the condition of the for loop. Even if I make it i>0...
Photochronograph asked 18/10, 2012 at 16:33

3

Solved

In the following type of code is there a sequence point between each variable construction, or is the result undefined? int a = 0; int b = a++, c = a++; I wasn't able to find in the standard a s...
Fadden asked 20/6, 2011 at 15:55

3

Solved

I was reading C Programming Language and found this sentence: The commas that separate ... variables in declarations ... are not comma operators, and do not guarantee left to right evaluation. ...

1

The title should clarify what my confusion is about. I'd like to use this question to get a comprehensive answer which helps me understand how the comma operator works with decltype within SFINAE c...

2

Solved

From this former question When all does comma operator not act as a comma operator?, I understood that commas inside a function call can only act as expression sperator. But from the code below, it...
Herzberg asked 19/12, 2017 at 13:38

15

Solved

I read this question about the "comma operator" in expressions (,) and the MDN docs about it, but I can't think of a scenario where it is useful. So, when is the comma operator useful?
Springing asked 6/3, 2012 at 7:27

1

The 2nd edition of C++ Templates - The Complete Guide features the following footnote at page 436 (my bold): Except that decltype(call-expression) does not require a nonreference, non-void return ...
Agnola asked 27/9, 2021 at 20:4

2

Solved

Talk is cheap; show me the code. // equals to this.test = "inside window" var test = "inside window"; function f () { console.log(this.test) }; var obj = { test: "inside object", fn: f }...
Externality asked 4/9, 2020 at 8:51

2

Solved

I am quite confused with the comma operator. I have never seen such code with such syntax? but I am curious if it useful at any place? why is it deprecated in c++20? #include <iostream> int m...
Confessedly asked 20/7, 2020 at 16:42

1

Solved

it's known that to declare multiple variables, one uses a format like: let k = 0, j = 5 /*etc....*/ It's also known that to execute multiple statements in one line (which is useful for arrow fu...
Galligaskins asked 7/4, 2020 at 10:32

1

Solved

Looking at std::for_each_n's possible implementation: template<class InputIt, class Size, class UnaryFunction> InputIt for_each_n(InputIt first, Size n, UnaryFunction f) { for (Size i...
Frill asked 18/2, 2020 at 13:28

7

Solved

With reference to Comma-Separated return arguments in C function [duplicate] , x=x+2,x+1; will be evaluated as x=x+2; However, in case of the following code #include<stdlib.h> #inclu...
Betweenwhiles asked 14/9, 2019 at 20:32

2

Solved

This seems such a simple question, but something I've not examined for ages in my own style... When initializing variables separated by a comma, I've assumed the following to be an unsafe practice:...
Merits asked 15/1, 2019 at 13:55

1

Solved

Consider a simple example: int foo() { return 3; } template <int> struct Bar {}; int a; int main() { int b; //Bar<((void)foo(), 1)> bar1; //case 1. compilation error as expected ...
Counterscarp asked 3/12, 2018 at 18:28

11

Solved

I see questions on SO every so often about overloading the comma operator in C++ (mainly unrelated to the overloading itself, but things like the notion of sequence points), and it makes me wonder:...
Squelch asked 9/4, 2011 at 0:45

3

I can write the code if(1) x++, y++; instead of if(1) {x++; y++;}, but in some cases it does not work (see below). It would be nice if you tell me about this. int x = 5, y = 10; if (x == 5) x++, ...
Ruella asked 21/8, 2018 at 6:38

1

Solved

I'm trying to understand how the comma operator (,) works in JavaScript, it seems to have a different behaviour when it's not put between parenthesis. Can someone explain me why ? Exemple...
Shocking asked 4/6, 2018 at 10:31

1

Solved

Using Paul Fultz II's solution in the post C-preprocessor recursive macro, I'd like to expand an unlimited number of parenthesized macro arguments, e.g. #define MY_CHAIN (alpha) (beta) (gamma) ...
Diathermic asked 12/3, 2018 at 12:45

4

Solved

I wrote the code about sizeof operator. If I write something like: #include <stdio.h> int main() { char a[20]; printf("%zu\n", sizeof(a)); return 0; } Output: 20 // Ok, it's fin...
Cymric asked 18/10, 2017 at 9:38

3

Solved

#include<stdio.h> int main(void) { int a; a = (1, 2), 3; printf("%d", a); return 0; } output: 2 Can any one explain how output is 2?
Erlond asked 12/9, 2017 at 13:6

9

I came across a for-loop in code that looks like this: for ( argc--, argv++; argc > 0; argc--, argv++ ) How does it work? Normally a for loop looks like this: for (initialization; condition...
Wolsey asked 17/8, 2017 at 11:37

2

Solved

consider the following example program: #include <iostream> using namespace std; struct t { ~t() {cout << "destroyed\n"; } }; int main() { cout << "test\n"; t(), cout <<...

3

Solved

I'm putting together a C++-based assignment for a class I'm teaching. I have a function I'm exporting to students that I'd like them to call at various points in their program so that, during gradi...
Jaconet asked 19/1, 2017 at 18:35

3

Solved

Prog 1: #include<stdio.h> int main() { int i=0; while(i<=8,i++); printf("%d",i); return 0; } Prog 2: #include<stdio.h> int main() { int i=0; while(i++,i<=8); ...
Lamppost asked 12/1, 2017 at 11:5

© 2022 - 2025 — McMap. All rights reserved.