Right Click to Search

Tuesday, May 25, 2024

Comma Operator : Lowest Precedence | Returns Righmost Operand


Comma Operator : Lowest Precedence | Returns Righmost
#include<stdio.h>
void main()
{
int a=1,b=2;
int k;
k = (a,b);
printf("%d",k);
}
  1. Comma Operator has Lowest Precedence. [Priority] i.e evaluated at last .
  2. Comma operator returns the value of the rightmost operand.
  3. Comma Operator Can acts as -

    • Operator  : In the Expression
    • Separator : Declaring Variable , In Function Call Parameter List

In the Above Example -
1 :  Comma as Seperator
int a=1,b=2;
It can acts as Seperator in -
  • Function calls 
  • Function definitions 
  • Variable declarations 
  • Enum declarations
2 : Comma as Operator
k = (a,b);

Different Typical Ways of Comma as Operator :
int a=1,b=2,c;

Way 1 :
c = (a,b);
  • c = Value Stores in b . = 2
Way 2 :
c = a,b;
  • c = Value Stores in a . = 1

Tags / Keywords : | ,

Stumble
Delicious
Technorati
Twitter
Facebook

0 Comments:

Post a Comment

Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email

 

Learn C Programming Copyright © 2010 LKart Theme is Designed by Lasantha, Free Blogger Templates