comma and semi colon

This is a discussion on comma and semi colon within the C Programming forums, part of the General Programming Boards category; Is there a difference in the functionality between the comma(,) and the semi colon( operators?...

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    70

    comma and semi colon

    Is there a difference in the functionality between the
    comma(,) and the semi colon( operators?

  2. #2
    Registered User
    Join Date
    May 2004
    Posts
    127
    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.

  3. #3
    /*enjoy*/
    Join Date
    Apr 2004
    Posts
    159
    difference >>>
    exemple
    #include <math>
    int main()
    {
    pow(10,,9);
    }

    ;==> define end of instruction
    ,==>separate tow argument 10 and 9

    ------------------------------------------------------------------------------------------

  4. #4
    /*enjoy*/
    Join Date
    Apr 2004
    Posts
    159
    exuse me for mistake
    Code:
    pow(10,9);

  5. #5
    Registered User
    Join Date
    May 2004
    Posts
    127
    Quote Originally Posted by enjoy
    difference >>>
    exemple
    #include <math>
    int main()
    {
    pow(10,,9);
    }

    ;==> define end of instruction
    ,==>separate tow argument 10 and 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.

  6. #6
    /*enjoy*/
    Join Date
    Apr 2004
    Posts
    159

    ok

    =====>
    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

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,335
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #8
    Registered User
    Join Date
    May 2004
    Posts
    70
    in the code
    Code:
    int a = 10, 20;  // comma as an operator
    printf( "%d\n", a );  // comma as a separator
    , and ; are both operators, so where is ;(semi colon) used as a seperator or a puntuation mark.

    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)

  9. #9
    Registered User
    Join Date
    May 2004
    Posts
    127
    >, 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.

  10. #10
    Registered User
    Join Date
    May 2004
    Posts
    70
    ok
    i kind of understand it now

    what about in this code
    Code:
    while( ch = getchar(), ch >=0)
    the comma is a seperator?

    can you provide an example where the comma is an operator?

  11. #11
    Registered User
    Join Date
    May 2004
    Posts
    70
    if the ; is a seperator
    does thie mean we can actually ignore the last ;

    so we could have code like


    ....
    funtion_a;
    function_b

  12. #12
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    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.

  13. #13
    Registered User
    Join Date
    May 2003
    Posts
    161
    Quote Originally Posted by studentc
    ok
    i kind of understand it now

    what about in this code
    Code:
    while( ch = getchar(), ch >=0)
    the comma is a seperator?

    can you provide an example where the comma is an operator?
    In that code, the comma is an operator. The comma would be a separator, for example, in a function call:
    Code:
      printf("%s", buf);
    Edit:

    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.

  14. #14
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by studentc
    if the ; is a seperator
    does thie mean we can actually ignore the last ;

    so we could have code like
    ....
    funtion_a;
    function_b
    No, you can't ignore the last one, but you could replace the first one with a comma:
    Code:
    function_a( ),
    function_b( );
    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21