Difference between c structure and c++ structure

Discussion in 'C++' started by raghunandan_1081@yahoo.com, Mar 18, 2006.

  1. Guest

    Hi guys, can you please tell me what is the Difference between c
    structure and c++ structure
    , Mar 18, 2006
    #1
    1. Advertising

  2. Bob Hairgrove, Mar 18, 2006
    #2
    1. Advertising

  3. None of the eight questions in page under FAQ link match question
    asked, in my opinion. I suppose you could interpret the OP's question
    to be a comparison between C struct and C++ class, but I read OP's
    question as a comparison between C struct and C++ struct.

    One difference between C struct and C++ struct is that C++ struct can
    have methods inside. Another difference is that parts of C++ struct
    can be "hidden" by being made private.

    Opalinski
    http://www.geocities.com/opalpaweb
    opalinski from opalpaweb, Mar 18, 2006
    #3
  4. Kai-Uwe Bux Guest

    opalinski from opalpaweb wrote:

    > None of the eight questions in page under FAQ link match question
    > asked, in my opinion. I suppose you could interpret the OP's question
    > to be a comparison between C struct and C++ class, but I read OP's
    > question as a comparison between C struct and C++ struct.


    Since the only difference between a C++ struct and a C++ class is the
    default access (public for struct, private for class), the explanation in
    "what is a class" together with "what's the difference between the keywords
    struct and class" should answer the question of the OP (assuming the OP
    knows C structs).

    > One difference between C struct and C++ struct is that C++ struct can
    > have methods inside. Another difference is that parts of C++ struct
    > can be "hidden" by being made private.



    Best

    Kai-Uwe Bux
    Kai-Uwe Bux, Mar 18, 2006
    #4
  5. > Since the only difference between a C++ struct and a C++ class is the
    > default access (public for struct, private for class), the explanation in
    > "what is a class" together with "what's the difference between the keywords
    > struct and class" should answer the question of the OP (assuming the OP
    > knows C structs).


    I agree. Good point. With the above directions OP will be fine.

    Opalinski

    http://www.geocities.com/opalpaweb/
    opalinski from opalpaweb, Mar 18, 2006
    #5
  6. osmium Guest

    <> wrote:

    > Hi guys, can you please tell me what is the Difference between c
    > structure and c++ structure


    The syntax for using a struct is different in C than C++.

    In C++ struct is a type, and can be referred to much like an int. Not so in
    C.
    osmium, Mar 18, 2006
    #6
  7. On Sat, 18 Mar 2006 06:28:01 -0800, "osmium" <>
    wrote:

    ><> wrote:
    >
    >> Hi guys, can you please tell me what is the Difference between c
    >> structure and c++ structure

    >
    >The syntax for using a struct is different in C than C++.
    >
    >In C++ struct is a type, and can be referred to much like an int. Not so in
    >C.
    >


    Actually it is also a type, except that you have to prefix every use
    of the name with the keyword "struct" unless you declare it as a
    typedef.

    As you say, of course, the syntax is different, but types in C have
    different semantics than in C++ anyway.

    --
    Bob Hairgrove
    Bob Hairgrove, Mar 18, 2006
    #7
  8. Gimmmo Guest

    On Sat, 18 Mar 2006 15:48:10 +0100, Bob Hairgrove wrote:

    > On Sat, 18 Mar 2006 06:28:01 -0800, "osmium" <>
    > wrote:
    >
    >><> wrote:
    >>
    >>> Hi guys, can you please tell me what is the Difference between c
    >>> structure and c++ structure

    >>
    >>The syntax for using a struct is different in C than C++.
    >>
    >>In C++ struct is a type, and can be referred to much like an int. Not so in
    >>C.

    >
    > Actually it is also a type, except that you have to prefix every use
    > of the name with the keyword "struct" unless you declare it as a
    > typedef.


    struct A {
    char x;
    int y;
    };

    struct A A1;

    struct A A2;
    A2.x = 1;
    A2.y = 600;

    In C:
    A1 = A2; <--- can do?
    If i'm not wrong, must use memcpy() byte by byte.

    In C++:
    A1 = A2; <--- can do?


    Rgds.
    Gimmmo, May 8, 2006
    #8
  9. ss10

    Joined:
    May 23, 2011
    Messages:
    1
    In C++ it is allowed to define functions as part of a struct where as you can not define function in C structures.
    ss10, May 23, 2011
    #9
  10. Lal Bahadur Singh

    Joined:
    Nov 11, 2011
    Messages:
    1
    1>In C: structure is just data container.

    In C++: structure is almost identical to class. There is only one difference between structure and class in C++ : data members in structure are by default public, and in class they are by default private.

    2>In c structure
    ~we can not have access specifiers
    ~can not have functions
    But in c++
    ~we can specify data as a public , private and protected

    3> we can add the opp concept to stuct in c++ but the reverse is not true.


    thanks & regards
    {LAL}:)
    Lal Bahadur Singh, Nov 11, 2011
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jakk
    Replies:
    4
    Views:
    12,132
  2. Shea Martin
    Replies:
    11
    Views:
    14,012
    DeltaOne
    Jun 5, 2005
  3. Santa
    Replies:
    1
    Views:
    1,074
    Mark A. Odell
    Jul 17, 2003
  4. PerlFAQ Server
    Replies:
    0
    Views:
    354
    PerlFAQ Server
    Jan 6, 2011
  5. PerlFAQ Server
    Replies:
    0
    Views:
    260
    PerlFAQ Server
    Apr 15, 2011
Loading...

Share This Page