Q:

Similar syntax but one shows error but another does not

Hiii all
I made this program today
int main()
{
   int a = 1,2; /* Shows error */
   int b = (1,2); /* No error */
}

Why first one shows error while second one does not? Just ( ) makes one program compile. Why?
--Shruti

A:

int a = 1,2; 2 is treated as a variable name which cannot start with a number, hence the error.
int b = (1,2); comma operator evaluates the operands from left to right and returns the last expression in the list i.e. 2

A:

Inside the parentheses, the language specifies an expression will occur.  In that case (b), the comma represents the comma operator from C.
Without parentheses, the language specifies that variable declarations are separated by commas.  In the example of a, the compiler (parser) is expecting additional variable declarations.

A:

The reason is in your first statement int a = 1,2; the comma is not parsed to be a sequence operator.  It is part of a declaration list and attempts to instantiate an integer variable named 2 which is not allowed by the language.
The parentheses in the second statement int b = (1,2); force the comma to be parsed as a sequence operator.

