Is there a difference in the functionality between the
comma(,) and the semi colon( operators?
Is there a difference in the functionality between the
comma(,) and the semi colon( operators?
The comma operator is an operator that can be used within expressions, the semicolon is simply punctuation for a statement. They perform fundamentally different roles, so an accurate comparison wouldn't make sense.
difference >>>
exemple
#include <math>
int main()
{
pow(10,,9);
}
;==> define end of instruction
,==>separate tow argument 10 and 9
------------------------------------------------------------------------------------------
exuse me for mistake
Code:pow(10,9);
You're (rightly) confused. The C language has a comma operator and a comma separator. The separator is what separates arguments of a function. It is not the comma operator though, it's merely punctuation, just like the semicolon.Originally Posted by enjoy
=====>
originally posted by Neuhart
You're (rightly) confused. The C language has a comma operator and a comma separator
Code:i want to explain the exemple but i know that
The separator is what separates arguments of a function. It is not the comma operator though, it's merely punctuation, just like the semicolon
Code:int a = 10, 20; // comma as an operator printf( "%d\n", a ); // comma as a separator
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
in the code
, and ; are both operators, so where is ;(semi colon) used as a seperator or a puntuation mark.Code:int a = 10, 20; // comma as an operator printf( "%d\n", a ); // comma as a separator
and is there any difference in the comma or semi colon operator
i was wondering if we could replace the , with the semi colon in this bit of code
Code:while( ch = getchar(), ch >=0)
>, and ; are both operators
No, they're both tokens. A comma has use as an operator or a punctuator depending on the context, but a semicolon is not an operator, ever.
>so where is ;(semi colon) used as a seperator or a puntuation mark.
Everywhere you see a semicolon, it's used as punctuation.
>and is there any difference in the comma or semi colon operator
Yes there is. One is an operator, one is not. I feel like I'm repeating myself.
>i was wondering if we could replace the , with the semi colon in this bit of code
No.
When writing a specialization, be careful about its location; or to make it compile will be such a trial as to kindle its self-immolation.
ok
i kind of understand it now
what about in this code
the comma is a seperator?Code:while( ch = getchar(), ch >=0)
can you provide an example where the comma is an operator?
if the ; is a seperator
does thie mean we can actually ignore the last ;
so we could have code like
....
funtion_a;
function_b
the semi colon is more then a separator. Its kind of like the period of a sentence. Without it one does not know where a sentence ends.
Pascal used the semi colon as a command separator but C uses it as a command terminator.
In that code, the comma is an operator. The comma would be a separator, for example, in a function call:Originally Posted by studentc
Edit:Code:printf("%s", buf);
They key difference is that a comma (used either as an operator or as a separator) separates expressions while a semi-colon separates statements.
Last edited by thefroggy; 05-14-2004 at 12:07 PM.
No, you can't ignore the last one, but you could replace the first one with a comma:Originally Posted by studentc
Quzah.Code:function_a( ), function_b( );
Hope is the first step on the road to disappointment.