I am in the process of learning the C Programming Language and currently I am exploring the comma operator. I feel that I am slowly wrapping my mind around this operator. I found a good discussion on this operator here:
What does the comma operator , do?
I also found several examples on how this operator can be used:
#include<stdio.h>
int main()
{
int i;
i = (1,2,3);
printf("i:%d\n",i);
return 0;
}
And
#include<stdio.h>
void main()
{
int num1 = 1, num2 = 2;
int res;
res = (num1, num2);
printf("%d", res);
}
However, I recently ran across an unrelated example where the author happened to be using a comma operator and I am confused as to how it is being used in the example.
#include <stdio.h>
#include <stdlib.h>
struct date
{
int month;
int day;
int year;
};
struct date foo(struct date x)
{
++x.day;
return x;
}
int main(void)
{
struct date today = {10, 11, 2004};
struct date *newDate, foo(); // comma operator?
return 0;
}
The thing that is throwing me off is that after the comma operator, it appears that the foo() function is being called; however, the foo() function is declared to take one parameter, specifically of struct date. How is this function being called without any parameters and how does the comma operator fit into this example? Does the comma operator somehow pass the newDate pointer into foo()? Any insight would be appreciated. Cheers.