Comma Operator - Devbhoomi

FREE JOB ALERT & ONLINE TUTORIALS

Hot

Post Top Ad

Sunday 5 November 2017

Comma Operator

The comma operator has left-to-right associativity. Two expressions separated by a comma are evaluated left to right. The left operand is always evaluated, and all side effects are completed before the right operand is evaluated.
  • The comma operator is mainly useful for obfuscation.
  • The comma operator allows grouping expression where one is expected.
  • Commas can be used as separators in some contexts, such as function argument lists.
Example :

    #include <stdio.h>
    int main ()
    {
    int i = 10, b = 20, c= 30;

    // here, we are using comma as separator
    i = b, c;

    printf("%i\n", i);

    // bracket makes its one expression.
    // all expression in brackets will evaluate but
    // i will be assigned with right expression (left-to-right associativity)
    i = (b, c);
    printf("%i\n", i);

    return 0;
    }

Output :
    20
    30

No comments:

Post a Comment

Post Top Ad