Linked Questions
210 questions linked to/fromWhat does the comma operator , do?
93votes
20answers
24kviews
Uses of C comma operator [duplicate]
You see it used in for loop statements, but it's legal syntax anywhere. What uses have you found for it elsewhere, if any?
35votes
7answers
3kviews
Why is the return value of the fun function 8 instead of 7? [duplicate]
With reference to Comma-Separated return arguments in C function [duplicate],x=x+2,x+1;will be evaluated asx=x+2; However, in case of the following code#include<stdlib.h>#include<...
39votes
3answers
4kviews
Comma operator in c [duplicate]
#include<stdio.h> int main(void) { int a; a = (1, 2), 3; printf("%d", a); return 0;}output: 2Can any one explain how output is 2?
26votes
1answer
2kviews
What does a comma mean inside an 'if' statement? [duplicate]
Consider:for (auto i = 0; i < g.size(); ++i) for (auto j = 0; j < g.size(); ++j) if (g[i][j] == 0) dfs(g, i, j), ++regions;return regions;I don't like one line code. What does the code ...
11votes
3answers
12kviews
C Programming - comma operator within while loop [duplicate]
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&...
8votes
4answers
3kviews
Comma-Separated return arguments in C function [duplicate]
While completing a C programming test, I was given a question regarding the expected output from a function which seem to return two values. It was structured as follows:int multi_return_args(void)...
5votes
4answers
592views
if(a,b,c,d) how does this work? [duplicate]
int main(void){ int a=0, b=20; char x=1, y=10; if(a,b,x,y) printf("bye"); return 0;}How does "if" condition in the above code work work?Would the value of "y" be only considered by "if"...
7votes
7answers
2kviews
Suggest a book for tricky questions in C example unusual if condition [duplicate]
Possible Duplicate: What does the ',' operator do in C? Ok I had an interview today and they asked me what should be the output of the following code#include<stdio.h>int main (){...
6votes
1answer
6kviews
In c, can a switch statement have 2 arguments? [duplicate]
int main(){ switch(1,2) { case 1:printf("1");break; case 2:printf("2");break; default: printf("error");break; }}Is this valid in c?I thought it shouldn't be , but when ...
4votes
3answers
623views
segmentation fault when using double brackets with printf [duplicate]
#include<stdio.h>#define POOLNAME_FMT "Hello"void main() { printf((POOLNAME_FMT "Cannot allocate %d bytes" POOLNAME_FMT "in pool not enough memory",5));}Why does it give segmentation ...
4votes
4answers
802views
C function call followed by a comma separator [duplicate]
I was reading some material about errors that should be avoided when writing C programs and I came across the following code:#include <stdio.h>void foo(int param){ printf("foo is called\n"...
2votes
5answers
5kviews
How does for(i=0; i<5; x=(i++,a++)) work [duplicate]
I can't understand how this works and why it produces the following output.int main(){ int i=0; int a=5; int x=0; for(i=0; i<5; x=(i++,a++)) { printf("i=%d a=%d x=%...
1vote
7answers
1kviews
while loop output for multiple condition [duplicate]
main(){ int i=0,j=0; while(i<5,j<10) { i++; j++; } printf("%d,%d,",i,j);}output: 10,10int main(){ int x=2,y=2; while(x<=5,y<=3) ...
4votes
2answers
333views
What does the [x,y] symbol mean in a multidimensional array access? [duplicate]
I'm studying C and I came across the code below. The printed results are always the same for all the printf calls. What does [x,y] mean? A memory address or something else?printf("%d ", array[0,0]...
2votes
2answers
427views
Is it possible to pass two arguments in c? [duplicate]
I have written a C program where I declared a function reverse(int i). When I compile and run the program, it runs fine despite passing two arguments like this reverse((i++, i)). Why doesn't this ...




