assig array != struct ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • langog.info@gmail.com

    #1

    assig array != struct ?

    hi:
    in c,i use :

    int a[5],b[5]={1,2,3,4,5};
    struct {
    int c[5];
    }aaa,bbb;

    bbb.c[0]=bbb.c[1]=bbb.c[2]=bbb.c[3]=bbb.c[4]=2;

    1) a=b; //compile error;
    2) aaa=bbb

    1.what's differ between 1),2)?
    2.why i can't init bbb by bbb.c[5]={2,2,2,2,2};

    thx!!

  • Richard Heathfield

    #2
    Re: assig array != struct ?

    langog.info@gma il.com said:
    hi:
    in c,i use :
    >
    int a[5],b[5]={1,2,3,4,5};
    struct {
    int c[5];
    }aaa,bbb;
    >
    bbb.c[0]=bbb.c[1]=bbb.c[2]=bbb.c[3]=bbb.c[4]=2;
    >
    1) a=b; //compile error;
    2) aaa=bbb
    >
    1.what's differ between 1),2)?
    You can't assign to an array. You /can/ assign to a struct. Why? Well,
    because. There doesn't seem to be any better reason than that. It's
    just one of them things.
    2.why i can't init bbb by bbb.c[5]={2,2,2,2,2};
    struct {
    int c[5];
    } aaa, bbb = { { 2, 2, 2, 2, 2 } };

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999

    email: rjh at the above domain, - www.

    Comment

    • langog.info@gmail.com

      #3
      Re: assig array != struct ?

      On 3ÔÂ16ÈÕ, ÏÂÎç1ʱ54·Ö, Richard Heathfield <r...@see.sig.i nvalidwrote:
      langog.i...@gma il.com said:
      >
      hi:
      in c,i use :
      >
      int a[5],b[5]={1,2,3,4,5};
      struct {
      int c[5];
      }aaa,bbb;
      >
      bbb.c[0]=bbb.c[1]=bbb.c[2]=bbb.c[3]=bbb.c[4]=2;
      >
      1) a=b; //compile error;
      2) aaa=bbb
      >
      1.what's differ between 1),2)?
      >
      You can't assign to an array. You /can/ assign to a struct. Why? Well,
      because. There doesn't seem to be any better reason than that. It's
      just one of them things.
      >
      2.why i can't init bbb by bbb.c[5]={2,2,2,2,2};
      >
      struct {
      int c[5];
      >
      } aaa, bbb = { { 2, 2, 2, 2, 2 } };
      >
      --
      Richard Heathfield
      "Usenet is a strange place" - dmr 29/7/1999http://www.cpax.org.uk
      email: rjh at the above domain, - www.
      thx rjh!!
      but the answer without reason.
      if i want to change the value of bbb ,how to do it simply?
      can u figure the c's object modle in memory?

      Comment

      • Nick Keighley

        #4
        Re: assig array != struct ?

        langog.info@gma il.com wrote:
        On 3ÔÂ16ÈÕ, ÏÂÎç1ʱ54·Ö, Richard Heathfield <r...@see.sig.i nvalidwrote:
        langog.i...@gma il.com said:
        in c,i use :
        Could you not not use abbreviations like "u"? It is clearer if you use
        "I"
        rather than "i". Things are clearer if you use standard english rather
        than
        txt-speak.

        Also don't post the same thing multiple times.
        int a[5],b[5]={1,2,3,4,5};
        struct {
        int c[5];
        }aaa,bbb;
        bbb.c[0]=bbb.c[1]=bbb.c[2]=bbb.c[3]=bbb.c[4]=2;
        1) a=b; //compile error;
        2) aaa=bbb
        1.what's differ between 1),2)?
        You can't assign to an array. You /can/ assign to a struct. Why? Well,
        because. There doesn't seem to be any better reason than that. It's
        just one of them things.
        2.why i can't init bbb by bbb.c[5]={2,2,2,2,2};
        struct {
        int c[5];

        } aaa, bbb = { { 2, 2, 2, 2, 2 } };

        --
        Richard Heathfield
        "Usenet is a strange place" - dmr 29/7/1999http://www.cpax.org.uk
        email: rjh at the above domain, - www.
        don't quote .sigs (anything after "--<space>") unless you are
        commenting
        on them

        but the answer without reason.
        yep. The answer is "because" or "ask Dennis" (the designer of the
        language).

        if i want to change the value of bbb ,how to do it simply?
        I suppose you could set up a default value.

        struct
        {
        int c[5];
        } aaa, bbb, def_bbb = { { 2, 2, 2, 2, 2 } };

        /* do things to bbb */

        /* reset to default */
        bbb = def_bbb;

        can u figure the c's object modle in memory?
        "model"? Why? Why do you need to know this? What are you trying to do?
        The ints of C will be in increasing order in memory. Some types may
        need padding
        between the array elements, but this is unlikely with ints.


        --
        Nick Keighley

        Comment

        Working...