Special: comma, sizeof Operators in C
Lets discuss few special operator supported in C. This includes comma operator, sizeof operator, pointer operators (& and *) and member selection operators (. and ->). Pointer operators will be covered while discussing pointer and member selection operators will be covered with structure and unions.
Comma Operator in C
Comma operator represented by comma ( , ) accepts two operands. It is used to combined two or more statement into single statement. We can write compact statement using this operator. The statements separated by comma operator are executed one by one from left to right. it has least precedence during expression evaluation.
Above three statements can be combined using comma operator
int x=1, y=x+1, z=x+y; /* It will be evaluated from left to right */
Now what will the output of below program?
void main( )
z = (x=10, y=30, x+y);
printf( "z=%d", z ) ;
If your answer was 40 then you are correct. lets see how it has been calculated. First 10 is copied to x, then 20 is copied to y and after that x+y is calculated and finally result is stored in z.
sizeof() operator returns number of bytes occupied by variable or constant in the memory. The size of operator works on variables, constants and even on data types
sizeof(char) 1 byte
sizeof(int) 4 bytes
Don't be surprised if you get other result for above example because size of datatype is machine dependent.